PDA

Click to See Complete Forum and Search --> : Creating my own Function. Help please!


jesus4u
Feb 27th, 2001, 12:22 PM
What is the correct way to code the sum of these variables?

Dim intEarlyBird

Function EarlyRegPrice()
Dim intReg1, intReg2, intReg3

Select Case strReglType 'registration type from the first grouping
Case Individual
intReg1 = 105
Case Spouse
intReg1 = 95
Case ActivePulpitPastor
intReg1 = 75
Case SpecialStudentRate
intReg1 = 75
Case Else --
Response.Redirect "ErrorType.asp"

End Select

Select Case strReg2Type 'registration type from the second grouping
Case Individual
intReg2 = 105
Case Spouse
intReg2 = 95
Case ActivePulpitPastor
intReg2 = 75
Case SpecialStudentRate
intReg2 = 75
Case Else --
Response.Redirect "ErrorType.asp"

End Select

Select Case strReg3Type 'registration type from the third grouping
Case Individual
intReg3 = 105
Case Spouse
intReg3 = 95
Case ActivePulpitPastor
intReg3 = 75
Case SpecialStudentRate
intReg3 = 75
Case Else --
Response.Redirect "ErrorType.asp"

End Select


intEarlyBird = sum(intReg1 - intReg16)

Feb 27th, 2001, 12:53 PM
make intReg an array with 16 elements (I'll cal it strRegArray)

dim strRegArray(16) as string
dim intLoop as integer

Change your select statments to:
Select Case strReglType 'registration type from the first grouping
Case Individual
strRegArray(1) = 105
Case Spouse
strRegArray(1) = 95
Case ActivePulpitPastor
strRegArray(1) = 75

End Select

Select Case strReg2Type 'registration type from the second grouping
Case Individual
strRegArray(2) = 105
Case Spouse
strRegArray(2) = 95
Case ActivePulpitPastor
strRegArray(2) = 75

etc........


Then sum em up with the for loop:

For intLoop = 1 to 16
intEarlyBird = intEarlyBird + Cint(strRegArray(intLoop))

Next

jesus4u
Feb 27th, 2001, 01:44 PM
Thank you very much for the code!

You guys are the best!

Don't I have to start the array at (0) instead of (1)?

Feb 27th, 2001, 01:52 PM
Yes, 0 is the default, but you can start at any number you want (provided it is within the range specified).

so your array could be declared as

dim strRegArray(15) as string means there are 16 elements in the aray


or (I don't know why you would do this) you could start at 11 (but this will only allow you to place 5 items in the array).

jesus4u
Feb 27th, 2001, 02:11 PM
Now how do I correctly check the current date against a preset date in the future and based on that call this function EarlyPrice or the other function RegPrice?

Here is what I have:

Dim MyDate
Mydate = Date 'will return system date
If MyDate <= 'the rest is a clue to me!

jesus4u
Feb 27th, 2001, 02:56 PM
Thanks for the help!

But when I run the code, the browser gives me this error:
Error Type:
Microsoft VBScript compilation (0x800A0411)
Name redefined
/ReclaimAmerica.org/Conference/RegPrice.asp, line 4, column 4
Dim strRegArray(16)
---^

I have this same code duplicated on another .asp used to sum up numbers based on different criteria.
Is the problem that I named strRegArray(16) on two different pages using the <!-- #INCLUDE FILE.asp" --> statements?

Feb 27th, 2001, 03:02 PM
yes, you are getting that error because you have that variable already declared in an include.

jesus4u
Feb 27th, 2001, 03:04 PM
Now is this the correct way to call the functions?

'-- Call the Functions
MyDate = Date
If MyDate <= "03/31/01" Then
EarlyPrice()
Else RegPrice()