Help with IF THEN ELSE

Author Message
Highwayman

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 8/9/2007
  • Status: offline
Help with IF THEN ELSE Thursday, August 09, 2007 3:35 PM (permalink)
0
I'm fairly new to VBScript and I've written an asp page to dynamically create content from a text file.
 
Everything was running smoothly, and I had a statement near the bottom of the page in the HTML body to evaluate a condition.
 
If the value of "act_today" is less than that of "dayrun" write the value of "act_today" in red, else write it in black.
 
<td align="right"><% if (act_today)<(dayrun) then response.write("<font color='red'>" & (act_today)) else response.write(act_today) end if %></td>
 
This worked correctly and changed the colour of the output accordingly.
 
However, one of my calculations further up the script could have resulted in an error where the script would try to divide another variable by 0, so I put in the following statement to evaluate this condition.
 
If the value of "remain" is greater than 0, "dayrun" is the rounded result of "to_go" divided by "remain", else dayrun is equal to to_go
 
if (remain)>0 then dayrun=(Round((to_go/remain), 0)) else dayrun=to_go
 
This however has broken the 1st statement, and it always evaluates the condition as false...
 
anyone have any pointers or tips... I havent been able to solve this in a few days so far, and it's doing my head in to say the least
 
 
 
#1
    Highwayman

    • Total Posts : 2
    • Scores: 0
    • Reward points : 0
    • Joined: 8/9/2007
    • Status: offline
    RE: Help with IF THEN ELSE Thursday, August 09, 2007 4:41 PM (permalink)
    0
    I had a LONG look through the forums and found that converting the variable to the Double subtype fixed the problem.

    The 1st statement now reads...

    <td align="right"><% if (CDbl(act_today))<(CDbl(dayrun)) then response.write("<font color='red'>" & (act_today)) else response.write(act_today) end if %></td>

    Still not sure why adding the other evaluation changed the way it behaved... If somebody has the time to explain it, I'd be greatful
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9