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

How to convert string number to integer in vb

Status
Not open for further replies.

Technos

Programmer
Mar 15, 2002
47
US
hey,
I need to convert string number (which i'm extracting from string) to an integer in ASP code.
anybody help????
I tried
index= Int32.parse(strIndex)
also
index= Convert.ToInt32(strIndex)

but its giving me error objrct required
HELP PLEASE
THANKS
 
Description
Returns an expression that has been converted to a Variant of subtype Integer.
Syntax
CInt(expression)
The expression argument is any valid expression.

Remarks
In general, you can document your code using the subtype conversion functions to show that the result of some operation should be expressed as a particular data type rather than the default data type. For example, use CInt or CLng to force integer arithmetic in cases where currency, single-precision, or double-precision arithmetic normally would occur.
Use the CInt function to provide internationally aware conversions from any other data type to an Integer subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators.

If expression lies outside the acceptable range for the Integer subtype, an error occurs.

The following example uses the CInt function to convert a value to an Integer:

Dim MyDouble, MyInt
MyDouble = 2345.5678 ' MyDouble is a Double.
MyInt = CInt(MyDouble) ' MyInt contains 2346.


--------------------------------------------------------------------------------

Note CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.

--------------------------------------------------------------------------------

 
Thanks Guys,
index = CInt(strindex)
or
index = CLng(strindex)

Worked.
even val(strindex) didn't worked
 
And if you should need to convert a decimal, you can use
==========================================================

mstr = "1982.8827"

numval = cdbl(mstr)

==========================================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top