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)
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!
|
|
|
|
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)
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.
|
|
|
|
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)
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!
|
|
|
|
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)
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.
|
|
|
|
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)
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!
|
|
|
|
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)
<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>
|
|
|
|
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)
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!
|
|
|
|
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)
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!
|
|
|
|
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)
|
|
|
|