Question about Dim

klaus

Expert
Licensed User
Longtime User
I had the habit to declare local variables in subroutines, like.
Sub LoadInit
Dim I,v,vn,vt

In the natural frequency program http://www.b4x.com/forum/share-your...quency-calculation-mechanical-structures.html
I get following errror:
Dim I,v,vn,vt
Error description:
Regular variables cannot be redeclared.
Continue ?

Is the declaration of local variables in subroutines no more suitable ?

The program can be compiled (Windows) and runs without the error message.

I tried to reproduce it in a small program, but I dont get the error message.

Best regards.
 

agraham

Expert
Licensed User
Longtime User
It is because those variables are not local but global as they have already been declared in Sub Globals. Previously Dim in Subs was not actually supported and was ignored, now it is properly supported to enable typed local variables and is correctly complaining that you are trying to redeclare an already declared variable. Global arrays can be redeclared in a Sub to be of different sizes but the type and rank must remain as the original declarations in Globals.

@Erel - I think the error message could be made a bit less obtuse as

"Regular global variables cannot be redeclared."
 
Top