scope of dim statements

In this category you can exchange your programming questions and solutions.
Post Reply
PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

scope of dim statements

Post: # 1176Post PaPi
Wed Apr 16, 2014 12:50 pm

I`ve an problem:
In this program:
`--------------------------------
`dimtest by PaPi 16-04-2014
dim i as integer
dim j as integer
i=10
j=20
sub testsub(jj as integer)
dim i as integer
i=jj+jj
showmessage str$(i)
end sub

testsub(j)
showmessage "end"+str(i)
`-----------------------------
The fnxcompiler say :
error 1 line 8 Variable `i` already exists.

Try this, Marco!

But, I know that the outside and inside written
" dim i as integer "
instructions independent of each other. Is not that right?

PaPi

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

scope of dim statements

Post: # 1177Post Marco
Wed Apr 16, 2014 3:13 pm

They are independed if you usedthem not already, a global dimmed var in the root of the program overrules the ones in the subs.
To keep the global var global you can not use it in the subs.

if you have this posibility

dim i as integer
i=10
sub test(i as intger)
  i=20
  print i `` no acces to global that`s why it is blocked by an already exists error
end sub

best regards

PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

scope of dim statements

Post: # 1178Post PaPi
Wed Apr 16, 2014 4:00 pm

Thank you very mutch.
In short, can not use the same name for a global variable and a local variable at the same time. So this is a FNXBASIC features, as it is usually not the case (in other languages[ch8203][ch8203]).

best regards
PaPi

Post Reply