The 'shared' statement

Started by Charles Pegge, June 27, 2024, 03:44:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

In ancient times, TurboBasic / PowerBasic required functions to include a shared statement listing all the global variables it would use.

To facilitate the porting of this old source code, I have included this construct in OxygenBasic. If you use a shared statement it must include all the global variables used in the function or procedure. Otherwise it will report an error. If there is no 'shared' statement then OxygenBasic behaves as normal.

But this feature might also be useful in contemporary coding of large procedures, as a checklist for dependent variables.

(This feature was introduced in March 2024)

string s,t
t="World"
'
function f() as string
shared s,t
s="Hello "
return s+t
end function
'
print f() 'Hello World'

Zlatko Vid

also freeBasic and qb64 use it
so you may attract fauna on this way ...maybe

Charles Pegge

I'm looking at some ancient PB code of 30 years ago. It was a complete DOS based DBaseIII-like application.

sample procedure:
sub scrolls(v$,v%,y%,yo%,x%,xo%)
shared fcol%,bcol%
m%=1
call wordval(v$,m%,v%)
call wordval(v$,m%,y%)
call wordval(v$,m%,yo%)
call wordval(v$,m%,x%)
call wordval(v$,m%,xo%)
call word(v$,m%,w$):if lw% then fcol%=val(w$)
call word(v$,m%,w$):if lw% then bcol%=val(w$)
end sub