Normal Topic Global Code subroutine error (Read 753 times)
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Global Code subroutine error
Aug 4th, 2011 at 2:51pm
Print Post Print Post  
Here is my Global Code section:
Code
Select All
// Global Code
Stat sComboColor as String
Stat sComboSize as String

sComboColor = "Red;Orange;Yellow;Green;Blue;Violet;Black;White;Brown"
sComboColor = @SortStringArray(sComboColor, 0)
PopulateListElement(Color, sComboColor)

sComboSize = "Micro;Tiny;Small;Medium;Big;Large;Huge;Gigantic"
sComboSize = @SortStringArray(sComboSize, 0)
PopulateListElement(Size, sComboSize)


SubRoutine srFailed(vFlavor as String)
@MsgBox("This does combine with a " + vFlavor + "flavor.","It will be Yucky!","")
End SubRoutine
 

====================================
When testing, I get the following error:
Error while parsing module " GLOBAL CODE ";
Statement or End-Of-File expected.
Line 23, position 1: SUBROUTINE
Subroutine srfailed(vflavor as string)
-------------------------------------------------------

I get the same error for any SubRoutine, I tried this smaller one with the same result.
Code
Select All
SubRoutine MyTest()
	@MsgBox("Test","","")
End SubRoutine 


What can be wrong in the earlier sections that prevent me from entering a SR?  If I move the SRs to the top before declaring the stat variables, I don't get the error.  It looks like there is a sequencing order for variables, sub routines, code lines?  If Yes, what are the rules, and where is that noted in the documentation?
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Global Code subroutine error
Reply #1 - Aug 4th, 2011 at 3:10pm
Print Post Print Post  
Hello obfusc88,

Variable declarations and Function/Subroutine declarations need to come before the regular code. The following quote is from page 50 of the Programming guide and it may be listed in a few more places as well.

Quote:
The declaration part of a program must always come before any statements:


The following code will compile for you.

Code
Select All
Stat sComboColor as String
Stat sComboSize as String

SubRoutine srFailed(vFlavor as String)
@MsgBox("This does combine with a " + vFlavor + "flavor.","It will be Yucky!","")
End SubRoutine

sComboColor = "Red;Orange;Yellow;Green;Blue;Violet;Black;White;Brown"
sComboColor = @SortStringArray(sComboColor, 0)
PopulateListElement(Color, sComboColor)

sComboSize = "Micro;Tiny;Small;Medium;Big;Large;Huge;Gigantic"
sComboSize = @SortStringArray(sComboSize, 0)
PopulateListElement(Size, sComboSize) 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Global Code subroutine error
Reply #2 - Aug 4th, 2011 at 3:32pm
Print Post Print Post  
Thanks Ray.

But in my original layout, as shown in my example, the declarations were first.
That was followed by initialization of the variables, some programming code, and then the subroutines.  That seems to be no different from what you are saying except you are putting SR before programming code and initializations.  What am I missing here?
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Global Code subroutine error
Reply #3 - Aug 4th, 2011 at 3:44pm
Print Post Print Post  
Hello,

Subroutines and Functions are also declarations. All declarations need to come before any regular code.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Global Code subroutine error
Reply #4 - Aug 4th, 2011 at 3:53pm
Print Post Print Post  
Subroutines and Functions are also declarations.

AHA!.  Thanks, now it is so obvious.  You're the man   Cool
  
Back to top
 
IP Logged