120ThingsIn20Years
Senior Member
I have some code that runs sometimes and sometimes halts with Error msg - "Return without GoSub".
It runs perhaps 19 out of 20 times (those numbers are just a guess)
The problem is I'm not sure if I can use return like this. I can get around it, but I'd like to know for future reference if this is what's causing the problem, or if it's something else. I've noticed the debugger doesn't always stop on the bit of code that's causing the problem, especially with Do Loops, so I guess it could be caused elsewhere.
The question is, can I have multiple returns if only one gets read?
The code looks like this...
It runs perhaps 19 out of 20 times (those numbers are just a guess)
The problem is I'm not sure if I can use return like this. I can get around it, but I'd like to know for future reference if this is what's causing the problem, or if it's something else. I've noticed the debugger doesn't always stop on the bit of code that's causing the problem, especially with Do Loops, so I guess it could be caused elsewhere.
The question is, can I have multiple returns if only one gets read?
The code looks like this...
Code:
GetCurrentModeData:{
if CurrentMode = 1 then
let ReportVariable = TodaysFeeds
let LEDVariable = ReportFeedsTodayLED
let LED2Variable = ReportFeedsTodayLED
let ReportPause = LongReportPause
return ' bail out because there's no need to go further
end if
if CurrentMode = 2 then
Readadc FeedSizePot,ReportVariable
ReportVariable = ReportVariable / 5
let LEDVariable = FeedSizeLED
let LED2Variable = FeedSizeLED
let ReportPause = ShortReportPause
return
end if
if CurrentMode = 3 then
Readadc FeedsPerDayPot, ReportVariable
ReportVariable = ReportVariable / 20
LEDVariable = FeedsPerDayLED
LED2Variable = FeedsPerDayLED
ReportPause = ShortReportPause
return
end if
if CurrentMode = 4 then
Readadc DawnPot, ReportVariable
ReportVariable = ReportVariable / 5
LEDVariable = FeedSizeLED
LED2Variable = FeedsPerDayLED
ReportPause = ShortReportPause
return
endif
if CurrentMode > MaxModes then 'if you have run out of modes
let CurrentMode = 1 'go back to the first mode
end if
return
}