Normal Topic Error using var in Global Code (Read 751 times)
drastixnz
Full Member
***
Offline


A Newbie....

Posts: 146
Location: New Zealand
Joined: Nov 29th, 2006
Error using var in Global Code
Aug 30th, 2007 at 8:47pm
Print Post Print Post  
Solution: Variables cannot be declared in Global Code using var. Use stat instead.

I have this price of code in the global code for the report, to select a date range for the report.

stat gsCompareDate as Date
var vTemp as String
vTemp = @Calendar(@Date, “Select an aging
date”)
If(@Len(vTemp) > 0)
{
gsCompareDate = @ToDate(vTemp)
}
Else
{
gsCompareDate = @Date
}

bit it tells me that the var is not allowed to be declared in global area.

help please

Drastixnz
Drastixnz
« Last Edit: Aug 30th, 2007 at 11:12pm by Hammer »  
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Why is this happening?
Reply #1 - Aug 30th, 2007 at 11:09pm
Print Post Print Post  
Move the static variable to the top of Global and make your code into a function in Global Code
Now you can call this function from any element by entering "fnCompareDate()" without the quotes.
------------------------------------
Code
Select All
stat gsCompareDate as Date


Function fnCompareDate() as String    //=====================
     var vTemp as String
     vTemp = @Calendar(@Date,"Select an aging date")
     If(@Len(vTemp) > 0) {
	    gsCompareDate = @ToDate(vTemp)
	    } Else {
	    gsCompareDate = @Date
	Return gsCompareDate
	    }
End Function			    //===================== 



---------
Notes:
1.  The code above is untested, based on original posting.
2.  Had to replace original invalid quote characters on @Calendar line.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Error using var in Global Code
Reply #2 - Aug 30th, 2007 at 11:13pm
Print Post Print Post  
Bob, you need a Return statement in that Function. Or, if you're not returning anything, make it a subroutine.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Error using var in Global Code
Reply #3 - Aug 30th, 2007 at 11:21pm
Print Post Print Post  
I was re editing while you posted, I am too slow  Roll Eyes and you are too quick. Grin

I think it is OK now.

  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged