[Info-vax] VAX BASIC global variables.
E Thump
ethump at gmail.com
Thu Oct 14 21:18:56 EDT 2021
On Friday, October 15, 2021 at 1:36:11 AM UTC+1, Arne Vajhøj wrote:
> On 10/14/2021 8:23 PM, E Thump wrote:
> > I come from BBC Basic where all variables are global unless
> > explicitly defined as local to a sub/proc.
> >
> > VAX BASIC seems to operate the opposite way; IE variables by default
> > are local. QB64 also seems to operate this way however in QB64, I am
> > able to DIM SHARED [var_name] which makes a variable accessible
> > globally.
> >
> > How do I accomplish the same in VAX BASIC? I want a variable declared
> > at the top to be common throughout all the code, SUBs and all. At
> > this time, I'm working with a single source file.
> >
> > I'm looking at the COMMON keyword but I can't see how that works for
> > what I want, if at all it does!
> This program print 3:
>
> program comdemo
> common (myarea) integer v
Alright, thanks so I was on the right track with COMMON... what's the significance of myarea then?
I changed my program to this but it doesn't work as I want:
=====
External SUB adder (integer,integer)
common (myarea) integer a
common (myarea) integer b
a=100
b=200
print "a+b before sub: ",a+b
call adder (10,20)
print "a+b after sub: ",a+b
end program
sub adder (integer c,integer d)
a=400
b=1000
print "a+b in sub: ",a+b
print "c+d in sub: ",c+d
end sub
=====
yields:
a+b before sub: 300
a+b in sub: 1400
c+d in sub: 30
a+b after sub: 300
More information about the Info-vax
mailing list