Local variable cannot hid global variable

Discussion in 'Questions (Windows Mobile)' started by jschuchert, Oct 29, 2009.

  1. jschuchert

    jschuchert Active Member Licensed User

    Here is code I am using:

    this code is in main module
    If StrLength(strbearing) = 5 Then 
    CallSub("modppc1.convertangle",strbearing, 112242)
    End If
    Here is the sub being called from module "modppc1"

    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
    If StrIndexOf(strBearing, "-",0) > 0 Then _
    dblAngle = dblAngle * (-

    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
  2. klaus

    klaus Expert Licensed 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.
  3. jschuchert

    jschuchert Active Member Licensed 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.

  4. klaus

    klaus Expert Licensed User

    Could you post your code so we could have a closer look at ?

    Best regards.
  5. jschuchert

    jschuchert Active Member Licensed 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.

  6. agraham

    agraham Expert Licensed 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".
  7. Erel

    Erel Administrator Staff Member Licensed User

    Note that the optimized compiler only supports CallSub calls with up to 3 parameters.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice