Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Compiling problem with 'goto'


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-08-2010, 04:40 AM
Knows the basics
 
Join Date: Sep 2009
Location: South Jordan, Utah
Posts: 66
Send a message via Skype™ to jschuchert
Default Compiling problem with 'goto'

Well, I'm back again. Everything was going so smoothly as I added features to my plotting routine. After the last addition (which ran fine in the IDE) I tried to compile but got the following error message:
Error CS0159...No such label within the scope of the goto statement. However, the label is there as indicated in the following code of mine. I really need to move past this so hope someone can figure out what is wrong. Thanks, guys.
Code:
Sub frmplotpoints_mousedown(j,k)
j=upltx+(j/screenw)*(lwrtx-upltx)
j=Format(j,sdecpl)
k=uplty-(k/screenh)*(uplty-lwrty)
k=Format(k,sdecpl)

If chktraverse.Checked =True Then 
txtpointid.Visible =True
Goto traversehere  'where the error occurs while compiling
End If

'txtpointid.Visible =True
txtpointid.Text =k & "   " & j
FileOpen(c,strfilename,cRead)
lineoftext=FileRead(c)
Do Until lineoftext=EOF
coord()=StrSplit(lineoftext,",")
If j >=coord(2)-5 AND j<=coord(2)+5 AND k>=coord(1)-5 AND k<=coord(1)+5 Then
pt=coord(0)
If intcounter=0 OR intcounter="" Then
invpoint1=pt
'areapt1=pt
End If 
If intcounter>0 Then
invpoint2=pt
areapt2=pt
End If
j=coord(2)
k=coord(1)
intcounter=intcounter+1
If chkpointid.Checked = True  Then
txtpointid.Visible =True
txtpointid.text="Pt " & coord(0) & "  N " & k & "  E " & j
Goto endthisplot
'End If
End If

If chkinverse.Checked =True Then
'If intcounter>0 Then
strbearing=invpoint1 & "*" & invpoint2
startinverse8
continueinverse
converttodms
txtpointid.Visible =True
txtpointid.Text = strNS & strdeg & Chr(176) & strmin & Chr(39) & strsec & Chr(34) _
& strEW & "  " & Format(dbldistance,sdecpl) 
invpoint1=invpoint2 'so inverses can continue between points
Goto endthisplot
End If
'End If

If chkplotarea.Checked =True Then
If areapt1=pt Then
dblnorth=coord(1)
dbleast=coord(2)
End If
If areapt2=pt Then
dblnortha=coord(1)
dbleasta=coord(2)
End If
Areasqft = Areasqft + (dblNorth * dbleasta - dblnortha * dblEast)
dblnorth=dblnortha
dbleast=dbleasta
Areasqft = Areasqft + (dblnorth * dbleasta - dblnortha * dbleast)
txtpointid.Visible =True
txtpointid.Text ="Area = " & Format(areasqft/2,sdecpl) & " sq.ft."
'End If
Goto endthisplot
End If

traversehere:   this is the label. Error message said no such 
'''If chktraverse.Checked =True Then
btntravplot.Visible =True
txtpointid.Visible =True
dblnorth=k
dbleast=j
dblnorth1=k
dbleast1=j
Goto endthisplot
'''End If  

End If     this finishes other code above 
lineoftext=FileRead(c)
Loop

endthisplot:
FileClose(c)
End Sub
I know the code is not very elegant but it works. There is a form with several checkboxes that are then activated according to this code. As I stated before, all is well when run within the IDE. I read the docs on the goto statement but really didn't understand what it was telling me about the scope equal or wider than the calling goto.

Although you can use Goto to jump between different subs it may cause unpredictable errors because the local variables will still be the variables of the previous sub.
Goto is best used to jump inside a sub.
The optimized compiler doesn't allow jumps between different subs, and the target label must be in a scope equal or wider to the calling Goto.

The jumping is done within the same sub.

Thanks for all the previous help and am hoping this is solvable.

Jim Schuchert
Reply With Quote
  #2 (permalink)  
Old 02-08-2010, 08:24 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 3,359
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by jschuchert View Post
but really didn't understand what it was telling me about the scope equal or wider than the calling goto.
Simply put it means that you can jump out of or within an If/End If block or For/Next loop but can't jump into one. Studiously refraining from commenting about the use of Goto at all you might consider making the problematic block of code a separate Sub to avoid the scoping problem.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #3 (permalink)  
Old 02-08-2010, 06:11 PM
Knows the basics
 
Join Date: Sep 2009
Location: South Jordan, Utah
Posts: 66
Send a message via Skype™ to jschuchert
Default

Thank you Agraham. I can see that the label was still within a long "if-then-end if" statement so I guess that caused the compiler to throw the error. I am aware of the dangers and poor coding practice of using "go to" but after the original code was written I began adding stuff and it just evolved. I solved the problem by adding another plotting form and avoiding the issue. I wish the IDE caught those things prior to making an 'exe'. Your explanation and advice will save me heartburn in the future. Thanks again. Incidentally, will the 'auto scale' compile help with various screen resolutions and sizes?

Jim Schuchert
Reply With Quote
  #4 (permalink)  
Old 02-09-2010, 08:20 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 3,359
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by jschuchert View Post
will the 'auto scale' compile help with various screen resolutions and sizes?
It should do in most cases if you also stick to using mageLib for any drawing/imaging. If the autoscaled image quality on high resolution devices is not good enough you will need to use ImageLibEx and some simple scaling of your own. If want to use the application on unusual screen sizes you may also need to perform some intervention.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with compiling Arrie Questions & Help Needed 6 10-25-2009 08:45 PM
Compiling problem J12345T Questions & Help Needed 2 05-26-2008 05:09 AM
Problem with compiling schimanski Questions & Help Needed 2 01-28-2008 05:47 PM
Compiling problem HARRY Questions & Help Needed 3 12-23-2007 10:26 AM
Goto problem klaus Questions & Help Needed 2 11-15-2007 01:28 PM


All times are GMT. The time now is 04:30 PM.


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