Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Variable doesn't keep value (internet explorer)

    Any help appreciated please:
    VB Script used in page to determine values from user input.
    The user enters (on a form) a gross value, this value I have called "bon"
    There is a threshold at which national contributions will decrease. This threshold is 610. I have set this value in a variable "ee11NI"
    If user enters value less than ee11NI then --one calc runs
    If user enters value greater than ee11NI then --second calc runs

    Here's my code that doesn't work:
    if (bon>ee11NI) then
    cpseeCont = ((ee11NI-ee0NI)*eeNI) + ((bon-ee11NI)*0.01) //1% when above upper limit
    else
    cpseeCont = (bon-ee0NI)*eeNI
    end if

    but here's a variation on that code that DOES work:
    if (bon-ee11NI)>0 then
    cpseeCont = ((ee11NI-ee0NI)*eeNI) + ((bon-ee11NI)*0.01) //1% when above upper limit
    else
    cpseeCont = (bon-ee0NI)*eeNI
    end if


    cpseeCont is variable for result
    ee0NI is set variable of 91
    ee11NI is set variable of 610
    eeNI is set variable of 0.11

    TIA
    Alan, Cheshire, UK

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Variable doesn't keep value (internet explorer)

    Does the first version never work, or does it work for some values, not for others?

    It might be that the first version does an alphabetic comparison instead of numeric, while the subtraction bon-ee11NI in the second version forces it to numeric.

  3. #3
    3 Star Lounger
    Join Date
    Apr 2001
    Location
    Warrington, Cheshire
    Posts
    355
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Variable doesn't keep value (internet explorer)

    Thanks Hans,
    Yep, irrespective of value entered in the error'd version, the
    if(bon>ee11NI)
    always return true.

    I just tried the following and it worked:
    if((bon*1)>(ee11NI*1)) then........

    seems the code was assuming text for the bon variable.
    I checked it out using:
    msgbox "bon is a " & TypeName(bon)
    msgbox "ee11NI is a " & TypeName(ee11NI)

    which returned
    bon is a string
    and
    ee11NI is a integer

    Doh! Just read through the Wrox reference book under "implicit type coercion".

    Many thanks.
    Alan, Cheshire, UK.

    Now that I've learnt something, can I go home??

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Variable doesn't keep value (internet explorer)

    > Now that I've learnt something, can I go home??

    Unless you're a medical resident, I assume you have left by now. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Do you think that all values entered in an HTML form using INPUT="TEXT" fields are interpreted by ASP (or whatever back-end processor you're using) as strings, regardless of their actual content (e.g., alpha, numeric, date)? Seems logical, but I'm too lazy to go look it up.

Posting Permissions

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