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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting variants

Status
Not open for further replies.

vizualz

Programmer
Joined
Aug 8, 2001
Messages
1
Location
US
Howdy...

Trying to convert an expression of subtype "string" to an "int." I'm basically requesting a value from my form which returns either an interger or a decimal. When it returns a decimal - say 1.5, it's type is a string. How can I covert? I've tried cint, int - no dice! Please help!
 
CInt should convert the string to an integer
CDbl will convert the string to a double. ( use this if your form number will not be a whole number)
There is no reason why these should not work.

Try to combine it with trim in case there are trailing whitespaces:

e.g. myInt = CInt(trim(Request.Form("myField"))) Mise Le Meas,

Mighty :-)
 
You should protect yourself from "bad" input
Code:
Dim intErr
On error resume next
    myInt = CInt(trim(Request.Form("myField"))) 
    intErr = Err.Number
On error goto 0
if intErr <> 0 then
........
End if [URL unfurl="true"]WWW.VBCompare.Com[/URL]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top