VBS Greater Than Problem

Author Message
Ivan Howard

  • Total Posts : 7
  • Scores: 0
  • Reward points : 0
  • Joined: 9/30/2011
  • Status: offline
VBS Greater Than Problem Monday, January 23, 2012 5:10 AM (permalink)
0
Hi All,
 
I am new to VBS and need some help please.
 
The problem I have is within the following code:
I have declared 5 variables... with the amount the variable shown in 4 of them for ease of use within this example.
 
 
Dim variableAnswer
Dim variable0
Dim variable7
Dim variable5000
Dim variable10000
 
variable0 = 0
variable7 = 7
variable5000 = 5000
variable10000 = 10000
 
If variable5000 >= variable10000 Then
variableAnswer = variable7
Else
variableAnswer = variable0
End If
 
msgbox variableAnswer
 
The problem I have is that the variableAnswer is ALWAYS populated with 7 and I don't know what I am doing wrong.
 
Any help will be greatly appreciated.
 
Thanks
Ivan
 
 
Sometimes me sits and thinks and sometimes me just sits!
 
#1
    59cobalt

    • Total Posts : 981
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:VBS Greater Than Problem Monday, January 23, 2012 5:38 AM (permalink)
    0
    Ivan Howard
    The problem I have is that the variableAnswer is ALWAYS populated with 7 and I don't know what I am doing wrong.
    With the code you posted above variableAnswer will always be populated with 0. If it gets populated with 7 you're doing something you omitted from your code sample.
     
    #2
      Ivan Howard

      • Total Posts : 7
      • Scores: 0
      • Reward points : 0
      • Joined: 9/30/2011
      • Status: offline
      Re:VBS Greater Than Problem Monday, January 23, 2012 5:45 AM (permalink)
      0
      Thanks 59cobalt for looking at this.
       
      I have checked the code letter by letter and not left anything out.  I have then isolated each variable and replaced it with actual values and think I have found where the problem may be.
       
      The actual value of variable10000 is 251000... so my question is, is there a limit in the value of the variable or do I need to make some sort of allowance or is there a new syntax/code word for numbers above a certain number?
       
      I can replace all other variables with the values and it works fine... it is only when this one is replaced, does it error.
       
      Thanks again.
       
      Ivan
       
      Sometimes me sits and thinks and sometimes me just sits!
       
      #3
        59cobalt

        • Total Posts : 981
        • Scores: 91
        • Reward points : 0
        • Joined: 7/17/2011
        • Status: offline
        Re:VBS Greater Than Problem Monday, January 23, 2012 5:57 AM (permalink)
        0
        If the value of variable10000 is 251000 you most definitely did not post the actual code you are using. The code you posted behaves as it should. I verified that before posting my reply. If you want help: start with posting the code that actually causes your problem instead of code that doesn't.
         
        #4
          Ivan Howard

          • Total Posts : 7
          • Scores: 0
          • Reward points : 0
          • Joined: 9/30/2011
          • Status: offline
          Re:VBS Greater Than Problem Monday, January 23, 2012 6:58 AM (permalink)
          0
          Thanks 59cobalt.
           
          The code I have is sensitive, hence the reason I posted something that I copied and changed - letter for letter.  I have stripped out the actual code code and it works.  I will now compare it and look at why it is not working in the main script.
           
          Thanks for your help.
           
          Sometimes me sits and thinks and sometimes me just sits!
           
          #5
            59cobalt

            • Total Posts : 981
            • Scores: 91
            • Reward points : 0
            • Joined: 7/17/2011
            • Status: offline
            Re:VBS Greater Than Problem Monday, January 23, 2012 7:08 AM (permalink)
            0
            <wild guess>Try adding something like
            WScript.Echo TypeName(variable5000) & vbNewLine & TypeName(variable10000)
            right before the comparison. Perhaps whatever's providing the values stored in those variables is giving you string values instead of integers. In that case you'd need to do an explicit type cast:
            variable5000 = CLng(...)
            to convert the number string to a (long) integer.</wild guess>
             
            #6
              Ivan Howard

              • Total Posts : 7
              • Scores: 0
              • Reward points : 0
              • Joined: 9/30/2011
              • Status: offline
              Re:VBS Greater Than Problem Monday, January 23, 2012 7:38 AM (permalink)
              0
              Excellent - thanks very much 59cobalt.  I will try this and hopefully it will work.  I wasn't sure how to do explicit type casts as I am used to declaring variables in VBA for Excel.
               
              Enjoy the rest of your day :)
               
              Sometimes me sits and thinks and sometimes me just sits!
               
              #7
                Ivan Howard

                • Total Posts : 7
                • Scores: 0
                • Reward points : 0
                • Joined: 9/30/2011
                • Status: offline
                Re:VBS Greater Than Problem Monday, January 23, 2012 8:07 AM (permalink)
                0
                Hi 59cobalt,
                 
                Just FYI - one of the numbers was a string.  I will remember how to check and rectify this in the future.  Thanks very much for all your help.
                 
                Ivan
                 
                Sometimes me sits and thinks and sometimes me just sits!
                 
                #8
                  59cobalt

                  • Total Posts : 981
                  • Scores: 91
                  • Reward points : 0
                  • Joined: 7/17/2011
                  • Status: offline
                  Re:VBS Greater Than Problem Monday, January 23, 2012 10:29 AM (permalink)
                  0
                  You're welcome.
                   
                  #9

                    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