Results 1 to 8 of 8

Thread: Creating my own Function. Help please!

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Talking

    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)

  2. #2
    Guest
    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

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Smile

    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)?

  4. #4
    Guest
    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).

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Talking

    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!

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Talking

    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?

  7. #7
    Guest
    yes, you are getting that error because you have that variable already declared in an include.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    Now is this the correct way to call the functions?

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width