Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Charles Pegge on June 27, 2024, 03:44:59 PM

Title: The 'shared' statement
Post by: Charles Pegge on June 27, 2024, 03:44:59 PM
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'
Title: Re: The 'shared' statement
Post by: Zlatko Vid on June 28, 2024, 07:52:59 AM
also freeBasic and qb64 use it
so you may attract fauna on this way ...maybe
Title: Re: The 'shared' statement
Post by: Charles Pegge on June 28, 2024, 11:16:41 AM
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