Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparisons

Status
Not open for further replies.

gerald

Programmer
Apr 10, 2000
152
US
Ok I am a little confused about the way VBScript handles variables in comparisons.<br><br>Lets say I have the following code:<br><br>Dim var1, var2<br><br>var1 = &quot;0&quot;<br><br>Do While var1 &lt; 5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write var1 & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var1 = var1 + 1<br>Loop<br><br>This will run as expected and print the value of var1 5 times<br><br>This code:<br><br>Dim var1, var2<br>var1 = &quot;0&quot;<br>var2 = 5<br><br>Do While var1 &lt; var2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write var1 & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var1 = var1 + 1<br>Loop<br><br>will not execute anything inside of the do/while loop<br><br>This code:<br><br>Dim var1, var2<br>var1 = &quot;0&quot;<br>var2 = &quot;5&quot;<br><br>Do While var1 &lt; var2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write var1 & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var1 = var1 + 1<br>Loop<br><br>will just keep going and going and never end until the server says it has been executing too long<br><br>--------------------------------------------------------<br><br>Basically what I want to do is take a range of numbers from an html form and iterate through them. When I request it from the form it comes to the variable as a string. <br><br>When I try to compare the numbers<br>If Number1 &lt; Number2 Then<br>&nbsp;...<br>End If<br><br>will not execute. and if i print the values of the numbers out, i will see that for instance, Number1 = 25 and Number2 = 30 so Number1 is less than Number2.<br><br>Im guessing that this is an issue with it being a string. So what I want to know is, how can I evaluate what I want to evaluate?<br>Supposedly all variables are variant in VBScript and I cannot find any commands that will convert between a string and a number.<br><br>Any information would be greatly appreciated. ;-)<br><br>It is possible that I am overlooking something very simple so be gentle. Heh. I am a C/C++ programmer thrown into a world of ASP and VBScript.<br><br><br><br><br>
 
Unfortunately, you can't declare variables with a particular type, but you can explicitly force a data type by using one of the conversion functions. In your case, if the value will never be greater than 32767 you can use Cint(), otherwise use Clng().<br><br>for example:<br><br>Dim var1, var2<br>var1 = &quot;0&quot;<br>var2 = 5<br><br>Do While Cint(var1) &lt; Cint(var2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Write var1 & vbcrlf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var1 = Cint(var1) + 1<br>Loop<br><br><br> <p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
 
Thank you that is exactly the solution I was looking for!<br>I actually found a workaround for the particular problem that I had but I am going to change that now to use this type because it makes more sense to me and to anybody else looking at my code.<br><br>Thanks again<br>Gerald<br>
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top