Normal Topic 1.14 Global Code Vars and Stats (Read 599 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
1.14 Global Code Vars and Stats
Jul 22nd, 2006 at 5:53pm
Print Post Print Post  
Will the Global Code functions included in SBasicCodeLibrary.db still work or do I need to change all the Vars to Stats?

I'm particularly interested in DaysBetweenDates
Code
Select All
/*
Returns an Int indicating the number of
days between vDate1 and vDate2
*/

FUNCTION DaysBetweenDates(vDate1 as Date, vDate2 as Date) As Int
var vRet as Int
var vD1 as Int
var vD2 as Int

	vD1 = @ToNumber(vDate1)
	vD2 = @ToNumber(vDate2)
	vRet = vD2 - vD1
	Return(vRet)

END FUNCTION 



Also, is there any difference between this function and
Code
Select All
NumberOfDays=@ToNumber(Date2 - Date1) 


where Date1 and Date2 are both date fields on my form, and NumberOfDay is a number field?
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: 1.14 Global Code Vars and Stats
Reply #1 - Jul 22nd, 2006 at 6:13pm
Print Post Print Post  
Scott,

Vars inside a function or subroutine do not need to be changed. If you don't get an error when you run Test, you don't need to change anything.

As to your second question, the difference between the two pieces of code you show is that the first one will work. The second will not. You need to convert both dates to numbers before subtracting them.

This will work:
Code
Select All
NumberOfDays = @ToNumber(Date2) - @ToNumber(Date1)  

  

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


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: 1.14 Global Code Vars and Stats
Reply #2 - Jul 22nd, 2006 at 6:18pm
Print Post Print Post  
Quote:
As to your second question, the difference between the two pieces of code you show is that the first one will work. The second will not. You need to convert both dates to numbers before subtracting them.

Thank you.  I will use the function as is.

Followup question...what will happen when the answer is "negative days"?  Say a customer pays me in advance of the creation of the invoice.  How will my Invoice Aging interpret this condition?

I think I'm gonna find out.... Smiley
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: 1.14 Global Code Vars and Stats
Reply #3 - Jul 22nd, 2006 at 6:28pm
Print Post Print Post  
Quote:
I think I'm gonna find out....


It works beautifully.  I get a negative number, just as sweet as pie.
  

**
Captain Infinity
Back to top
IP Logged