Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Local variable cannot hid global variable

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2009, 09:01 PM
Basic4ppc Veteran
 
Join Date: Sep 2009
Location: South Jordan, Utah
Posts: 237
Send a message via Skype™ to jschuchert
Default Local variable cannot hid global variable

Here is code I am using:

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

Code:
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
Reply With Quote
  #2 (permalink)  
Old 10-29-2009, 09:20 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

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.
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide
Reply With Quote
  #3 (permalink)  
Old 10-29-2009, 09:28 PM
Basic4ppc Veteran
 
Join Date: Sep 2009
Location: South Jordan, Utah
Posts: 237
Send a message via Skype™ to jschuchert
Default

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
Reply With Quote
  #4 (permalink)  
Old 10-29-2009, 09:50 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

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

Best regards.
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide
Reply With Quote
  #5 (permalink)  
Old 10-30-2009, 12:13 AM
Basic4ppc Veteran
 
Join Date: Sep 2009
Location: South Jordan, Utah
Posts: 237
Send a message via Skype™ to jschuchert
Default

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
Reply With Quote
  #6 (permalink)  
Old 10-30-2009, 09:27 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

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".
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #7 (permalink)  
Old 10-30-2009, 02:58 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,734
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

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

Quote:
Perhaps the error should be "Parameter name cannot hide global variable name".
Agreed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Meldung: Local variable cannot hide a global variable JOTHA German Forum 2 07-18-2009 11:34 AM
variable address robert black Questions (Windows Mobile) 2 12-24-2008 08:53 PM
Help on getting variable jeterry Questions (Windows Mobile) 2 11-11-2008 10:09 PM
Dim variable c% as Double colin9876 Basic4ppc Wishlist 8 05-28-2008 01:26 PM
LoadCSV from a variable nsidney Questions (Windows Mobile) 7 01-30-2008 01:29 AM


All times are GMT. The time now is 10:31 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0