Local variable cannot hid global variable

jschuchert

Active Member
Licensed User
Longtime User
Here is code I am using:

this code is in main module
B4X:
strbearing=modppc1.strdeg
If StrLength(strbearing) = 5 Then 
CallSub("modppc1.convertangle",strbearing, 1, 1, 2, 2, 4, 2)
End If

Here is the sub being called from module "modppc1"

B4X:
Sub convertangle(strbearing, a, b, c, d1, E, f)
'Dim stenths, icntr, dsnum, dtenths
intDnum = SubString(strBearing, a, b)
intmnum = SubString(strBearing, c, d1)
intsnum = SubString(strBearing, E, f)

dblAngle = intDnum + intmnum / 60 + intsnum / 3600
skipnext:
If StrIndexOf(strBearing, "-",0) > 0 Then _
dblAngle = dblAngle * (-1)

End Sub

"strbearing" is a global variable declared in the main module as public
"strdeg" is a global variable declared in modppc1 module. Neither are declared anywhere else so I don't know which 'local' variable is referred to in the message "local variable cannot hide global variable". This code works in other versions of basic.

Thanks for any help.. Jim Schuchert
 

klaus

Expert
Licensed User
Longtime User
The line:
Sub convertangle(strbearing, a, b, c, d1, E, f)

should be
Sub convertangle(Main.strbearing, a, b, c, d1, E, f)

Any variable used in anouther module must have as a prefix the name of
the module where it was declared.

Is "strdeg" declared as Public? If not that means that it is local to the modppc1 module?

Best regards.
 

jschuchert

Active Member
Licensed User
Longtime User
Thanks, Klaus, but I tried that already and it throws a syntax error. I know the problem is in that line but can't pinpoint it. Apparently the parameters are causing the error.

Jim
 

jschuchert

Active Member
Licensed User
Longtime User
When I remove the parameters from the sub, it doesn't choke. I am going to revise my code so that it only looks at "strbearing" for the manipulations I will make. If I still have problems, I will post the code. Thanks for your time.

Jim
 

agraham

Expert
Licensed User
Longtime User
Sub convertangle(strbearing, a, b, c, d1, E, f)

I think you can only get that error message when you name a parameter the same as a global variable. The error message is slightly misleading but the parameter names are actually declarations of local variables. If you refer to a global variable name anywhere else in a Sub then it uses the global and doesn't declare a new local variable.

Perhaps the error should be "Parameter name cannot hide global variable name".
 
Top