Check if a variable is an integrer. I'm getti

# Thread: Check if a variable is an integrer. I'm getti

1. Junior Member
Join Date
Dec 1969
Posts
16

## Check if a variable is an integrer. I'm getti

I know this is really basic, but my memory doesn&#039;t serve me so well here.. I don&#039;t remember the command to check weither a variable is an integrer. Something like this i suppose:<BR><BR>var=5<BR>if IsInt(var) then<BR>response.write("success!")<BR>else<BR>resp onse.write("faliure!")<BR>end if<BR><BR>what&#039;s the command? It is&#039;nt "IsInt". I&#039;m getting mad. Pleas help me with this simple problem.<BR>(I&#039;ve tried to find in all sorts of tutorials but i can&#039;t find it. When i search i get to many hits.)

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## If Int(var) = var Then <eom>

.<BR>

3. Junior Member
Join Date
Dec 1969
Posts
16

## What a shame. :) But thanx!

I missed that space. What a shame. :) Thanks anyway!

4. Junior Member
Join Date
Dec 1969
Posts
16

## Or..no, that's not it.

var="wrong"<BR>if IsInt(var) then <BR>response.write("success!") <BR>else <BR>response.write("faliure!") <BR>end if <BR><BR>this should show the faliure, not "Internal server error"

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## You said check for integer...

...and I assumed you meant you already knew you had *some* sort of number.<BR><BR>What you were probably thinking of is IsNumeric. But *that* only tests for numbers, including floating point numbers. So the full solution is:<BR><BR>&#060;%<BR>If isNumeric(var) Then<BR>&nbsp; &nbsp; If Int(var) = var Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Write "success"<BR>&nbsp; &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Write "failure"<BR>&nbsp; &nbsp; End If<BR>Else<BR>&nbsp; &nbsp; Response.Write "failure"<BR>End If<BR>%&#062;<BR><BR>Unlike Java/JavaScript/C/C++, VBS does not have any "shortcut" operators, so if you code:<BR><BR>If isNumeric(var) AND var=Int(var) Then<BR> <BR>you would *still* get a type mismatch error.<BR><BR>Incidentally, you should *NOT* be getting "internal server error." Check out these threads:<BR><BR>http://www.aspmessageboard.com/forum/showMessage.asp?M=256683&F=20&P=1 <BR><BR>http://www.aspmessageboard.com/forum/showMessage.asp?M=296565&F=20&P=1 <BR><BR>You *should* be getting a "type mismatch" error.<BR><BR>FINALLY... If you want a sneaky way to do it:<BR><BR>&#060;%<BR>chk = "nope"<BR>On Error Resume Next<BR>chk = Int( Var )<BR>On Error GoTo 0<BR>If chk = "nope" Then<BR>&nbsp; &nbsp; Response.Write "failure"<BR>Else<BR>&nbsp; &nbsp; Response.Write "success"<BR>End If<BR>...<BR>%&#062;<BR>

6. Junior Member
Join Date
Dec 1969
Posts
16

## Sorry. My bad. Now it works. Thanks alot again!

Thank you, my little hero! :)

#### Posting Permissions

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