Normal Topic Help with Array and Function in 'Global Area' (Read 692 times)
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Help with Array and Function in 'Global Area'
Feb 13th, 2008 at 8:09pm
Print Post Print Post  
Ok, I'm starting on my first Sesame application, and I'm working on a form that will help my company's sales reps estimate custom items. (We make custom banners and flags.) What we used to do in Q&A 4.0 was to put our estimating 'cheat sheets' into the F1 Help screens for each particular field. So a user would hit F1 and the cheat sheet would pop up, he or she would find the information they needed, input it, and then move on to the next field (and the already open help screen would remain open).

Now that I'm creating a new Sesame application based upon the old Q&A system, I want to handle that sort of information behind the scenes. So I decided on an array. The problem I'm having is that when I've created a static array in the Global Area of my form called 'SewnPricingArray'. I then wrote some code that would loop through the array and find the values I needed -- and that code worked.

Then I discovered subroutines and functions.  Huh

After writing some functions (in the global area) that streamlined my programming in other parts of the form, I decided to try and write a global function that would do the scanning of the 'SewnPricingArray' -- but it doesn't seem to work. It gave me an error indicating that the array hadn't been declared yet. So... I moved the 'array' information up to the top of the Global Area (including the calling of the array and insertion of all the values) but it still craps out.

Is there some particular way that array should be referenced in Functions that I'm not aware of, or is there a particular order in which things should be declared in the global area?

The following code throws up no errors:

Code
Select All
// The following function 'SquareFootageCalc()' does exactly that.
Function SquareFootageCalc(vSewnHeight as Double, vSewnWidth as Double) as Double
var vSquareFootage as Double
vSquareFootage = ((vSewnHeight * vSewnWidth)/144)
Return(vSquareFootage)
End Function

// The following 'Recalculate()' function retotals the entire sewn estimate.
Function Recalculate() as Money
var vNewTotal as Money
var vFinalTotal as Money
vNewTotal = 0
vFinalTotal = 0
vNewTotal = @ToMoney(@SUM(BASECOST,APPLIQUECOST,BLOWUPCOST,BORDERSCOST,OTHERCOSTS,REINFORCINGCOST,VELCROCOST,ARTWORKCOST,FRINGECOST,GROMMETSCOST))
vFinalTotal = vNewTotal * MULTIPLIERS
Return(vFinalTotal)
End Function

// The following 'TBLRCalc()' function computes the TBLR (Top/Bottom/Left/Right) cost for footage items.
// It should only be passed a single string (T, B, L or R) at a time.
// It needs some tweaking.
Function TBLRCalc(vVal as String, vCostPerFoot as Double) as Double
var vCost as Double
var vSewnWidth as Double
var vSewnHeight as Double

vCost = 0
vSewnWidth = SEWNWIDTH
vSewnHeight = SEWNHEIGHT

If vVal = "T" OR vVal = "B" //Use the SewnWidth in inches.
{
	vCost = vSewnWidth * (vCostPerFoot / 12)
}
Else
{
	If vVal = "L" OR vVal = "R"
	{
		vCost = vSewnHeight * (vCostPerFoot / 12)
	}
	Else
	{
		@Msg("The value submitted to TBLRCalc() function was not a T, B, L, or R!")
	}
}

Return(vCost) // vCost is the calculated cost, which should be either added or subtracted.
End Function

// Declare Variables - SewnPricing is an array that will contain all the values
// for base and element costs, for both single-sided and double-sided banners. The array
// has 10 rows and 5 columns.
stat SewnPricing as Array[10,5] of Double
// Now declare some global pricing variables, for estimates.
stat VelcroCostPerFoot as Double
stat GrommetCostPerGrommet as Double
stat WebbingCostPerFoot as Double
stat ReinforcedCornerCost as Double
stat InsideBorderCostPerFoot as Double
stat OutsideBorderCostPerFoot as Double
stat FringeCostPerFoot as Double
// And now fill the static cost variables.

VelcroCostPerFoot = 2.00
GrommetCostPerGrommet = .25
WebbingCostPerFoot = 1.00
ReinforcedCornerCost = 5.00
InsideBorderCostPerFoot = 3.00
OutsideBorderCostPerFoot = 2.00
FringeCostPerFoot = 1.50

// Now fill the array with the proper values.
// The first column is square footage. 2nd is base cost for 1sided, 3rd is base cost for 2sided.
// The 4th column holds per element costs for 1sided banners, 5th columns holds for 2sided.

SewnPricing[1,1] = 15; SewnPricing[1,2] = 157; SewnPricing[1,3] = 280; SewnPricing[1,4] = 2.6; SewnPricing[1,5] = 4.8
SewnPricing[2,1] = 24; SewnPricing[2,2] = 195; SewnPricing[2,3] = 335; SewnPricing[2,4] = 2.85; SewnPricing[2,5] = 5.4
SewnPricing[3,1] = 40; SewnPricing[3,2] = 250; SewnPricing[3,3] = 470; SewnPricing[3,4] = 4; SewnPricing[3,5] = 7
SewnPricing[4,1] = 60; SewnPricing[4,2] = 335; SewnPricing[4,3] = 615; SewnPricing[4,4] = 4.25; SewnPricing[4,5] = 7.8
SewnPricing[5,1] = 96; SewnPricing[5,2] = 470; SewnPricing[5,3] = 825; SewnPricing[5,4] = 5.65; SewnPricing[5,5] = 10.2
SewnPricing[6,1] = 150; SewnPricing[6,2] = 590; SewnPricing[6,3] = 1070; SewnPricing[6,4] = 6.1; SewnPricing[6,5] = 11
SewnPricing[7,1] = 216; SewnPricing[7,2] = 825; SewnPricing[7,3] = 1380; SewnPricing[7,4] = 7.2; SewnPricing[7,5] = 13.8
SewnPricing[8,1] = 300; SewnPricing[8,2] = 1115; SewnPricing[8,3] = 1945; SewnPricing[8,4] = 10.1; SewnPricing[8,5] = 18.1
SewnPricing[9,1] = 375; SewnPricing[9,2] = 1440; SewnPricing[9,3] = 2500; SewnPricing[9,4] = 12.1; SewnPricing[9,5] = 21.75
SewnPricing[10,1] = 600; SewnPricing[10,2] = 2200; SewnPricing[10,3] = 3775; SewnPricing[10,4] = 17; SewnPricing[10,5] = 30.85

// Our array is now populated with values.
 



Now, if I add update that code to this (highlighting the new code):

Code
Select All
// The following function 'SquareFootageCalc()' does exactly that.
Function SquareFootageCalc(vSewnHeight as Double, vSewnWidth as Double) as Double
var vSquareFootage as Double
vSquareFootage = ((vSewnHeight * vSewnWidth)/144)
Return(vSquareFootage)
End Function

// The following 'Recalculate()' function retotals the entire sewn estimate.
Function Recalculate() as Money
var vNewTotal as Money
var vFinalTotal as Money
vNewTotal = 0
vFinalTotal = 0
vNewTotal = @ToMoney(@SUM(BASECOST,APPLIQUECOST,BLOWUPCOST,BORDERSCOST,OTHERCOSTS,REINFORCINGCOST,VELCROCOST,ARTWORKCOST,FRINGECOST,GROMMETSCOST))
vFinalTotal = vNewTotal * MULTIPLIERS
Return(vFinalTotal)
End Function

// The following 'TBLRCalc()' function computes the TBLR (Top/Bottom/Left/Right) cost for footage items.
// It should only be passed a single string (T, B, L or R) at a time.

Function TBLRCalc(vVal as String, vCostPerFoot as Double) as Double
var vCost as Double
var vSewnWidth as Double
var vSewnHeight as Double

vCost = 0
vSewnWidth = SEWNWIDTH
vSewnHeight = SEWNHEIGHT

If vVal = "T" OR vVal = "B" //Use the SewnWidth in inches.
{
	vCost = vSewnWidth * (vCostPerFoot / 12)
}
Else
{
	If vVal = "L" OR vVal = "R"
	{
		vCost = vSewnHeight * (vCostPerFoot / 12)
	}
	Else
	{
		@Msg("The value submitted to TBLRCalc() function was not a T, B, L, or R!")
	}
}

Return(vCost) // vCost is the calculated cost, which should be either added or subtracted.
End Function

// Declare Variables - SewnPricing is an array that will contain all the values
// for base and element costs, for both single-sided and double-sided banners. The array
// has 10 rows and 5 columns.
stat SewnPricing as Array[10,5] of Double
// Now declare some global pricing variables, for estimates.
stat VelcroCostPerFoot as Double
stat GrommetCostPerGrommet as Double
stat WebbingCostPerFoot as Double
stat ReinforcedCornerCost as Double
stat InsideBorderCostPerFoot as Double
stat OutsideBorderCostPerFoot as Double
stat FringeCostPerFoot as Double
// And now fill the static cost variables.

VelcroCostPerFoot = 2.00
GrommetCostPerGrommet = .25
WebbingCostPerFoot = 1.00
ReinforcedCornerCost = 5.00
InsideBorderCostPerFoot = 3.00
OutsideBorderCostPerFoot = 2.00
FringeCostPerFoot = 1.50

// Now fill the array with the proper values.
// The first column is square footage. 2nd is base cost for 1sided, 3rd is base cost for 2sided.
// The 4th column holds per element costs for 1sided banners, 5th columns holds for 2sided.

SewnPricing[1,1] = 15; SewnPricing[1,2] = 157; SewnPricing[1,3] = 280; SewnPricing[1,4] = 2.6; SewnPricing[1,5] = 4.8
SewnPricing[2,1] = 24; SewnPricing[2,2] = 195; SewnPricing[2,3] = 335; SewnPricing[2,4] = 2.85; SewnPricing[2,5] = 5.4
SewnPricing[3,1] = 40; SewnPricing[3,2] = 250; SewnPricing[3,3] = 470; SewnPricing[3,4] = 4; SewnPricing[3,5] = 7
SewnPricing[4,1] = 60; SewnPricing[4,2] = 335; SewnPricing[4,3] = 615; SewnPricing[4,4] = 4.25; SewnPricing[4,5] = 7.8
SewnPricing[5,1] = 96; SewnPricing[5,2] = 470; SewnPricing[5,3] = 825; SewnPricing[5,4] = 5.65; SewnPricing[5,5] = 10.2
SewnPricing[6,1] = 150; SewnPricing[6,2] = 590; SewnPricing[6,3] = 1070; SewnPricing[6,4] = 6.1; SewnPricing[6,5] = 11
SewnPricing[7,1] = 216; SewnPricing[7,2] = 825; SewnPricing[7,3] = 1380; SewnPricing[7,4] = 7.2; SewnPricing[7,5] = 13.8
SewnPricing[8,1] = 300; SewnPricing[8,2] = 1115; SewnPricing[8,3] = 1945; SewnPricing[8,4] = 10.1; SewnPricing[8,5] = 18.1
SewnPricing[9,1] = 375; SewnPricing[9,2] = 1440; SewnPricing[9,3] = 2500; SewnPricing[9,4] = 12.1; SewnPricing[9,5] = 21.75
SewnPricing[10,1] = 600; SewnPricing[10,2] = 2200; SewnPricing[10,3] = 3775; SewnPricing[10,4] = 17; SewnPricing[10,5] = 30.85

// Our array is now populated with values.

// 'SewnPricingScan()' is a function that will scan the array 'SewnPricing' and find what I need.
Function SewnPricingScan(vFootage as Double, vColumn as Int) as Double
var vFoundValue as Double
var loop as Int
var Found as Int
loop = 1
Found = 0

While ((loop <= 10) AND (Found = 0))
{
	If SewnPricing[loop, 1] >= vSewnFootage
	{
		vFoundValue = SewnPricing[loop, vColumn]
		Found = 1
	}
	loop = loop + 1
}
Return(vFoundValue)
End Function
 



That new bit of programming gets the following error:

Quote:
"Statement or End-Of-File expected."
Line 95, position 1.


Immediately underneath, it shows the line starting my new function, with the caret under the 'f' in 'function'.
Also, this causes a kind of error cascade with all my programming boxes that make other function calls.
Commenting out the highlighted programming restores everything back to working order, no errors.
What am I doing wrong? Any help would be greatly appreciated. Smiley

(crosses fingers and hopes its not just some dumb typo)
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with Array and Function in 'Global Area'
Reply #1 - Feb 13th, 2008 at 8:22pm
Print Post Print Post  
Acebanner wrote on Feb 13th, 2008 at 8:09pm:
(crosses fingers and hopes its not just some dumb typo)

Hope for dumb typos. They're the easy ones to fix.  Smiley

In this case, you need to move your Function up above the executable code. Function/Subroutines are like variable declarations. They have to appear before any line of code that just runs.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Help with Array and Function in 'Global Area'
Reply #2 - Feb 13th, 2008 at 8:54pm
Print Post Print Post  
Hammer wrote on Feb 13th, 2008 at 8:22pm:
Acebanner wrote on Feb 13th, 2008 at 8:09pm:
(crosses fingers and hopes its not just some dumb typo)

Hope for dumb typos. They're the easy ones to fix.  Smiley

In this case, you need to move your Function up above the executable code. Function/Subroutines are like variable declarations. They have to appear before any line of code that just runs.




Ok, that's what's confusing to me. How can I have a function appear above the array that it references? Shouldn't the array declaration AND the contents of the array appear before the function? Or does it not matter?
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Help with Array and Function in 'Global Area'
Reply #3 - Feb 13th, 2008 at 9:20pm
Print Post Print Post  
Acebanner wrote on Feb 13th, 2008 at 8:54pm:
Ok, that's what's confusing to me. How can I have a function appear above the array that it references? Shouldn't the array declaration AND the contents of the array appear before the function? Or does it not matter?

It should appear below the array declaration, but before the executable lines where you are actually assigning values to the array.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Help with Array and Function in 'Global Area'
Reply #4 - Feb 14th, 2008 at 12:28am
Print Post Print Post  
Ah, ok, now it works.
Thanks a lot!  Smiley
  
Back to top
IP Logged