how to convert a string to an integer

# Thread: how to convert a string to an integer

1. amy
Senior Member
Join Date
Dec 1969
Posts
141

## how to convert a string to an integer

hi there, <BR><BR>how to convert the value of an element from QueryString to an integer? e.g. If the QueryString is: ?totalNum=29<BR>what i wanted to do was:<BR><BR>dim intSize<BR>intSize = Request.QueryString ("totalNum")<BR>dim aryTotalNum (intSize)<BR><BR>but the error msg i got from the last line was: Expected integer constant<BR><BR>thanx,<BR>

2. Member
Join Date
Dec 1969
Posts
34

## use CInt()

e.g. CInt(intSize)

3. Array Freak Guest

## RE: how to convert a string to an integer

No!<BR><BR>You must do this:<BR><BR>dim aryTotalNum <BR>redim aryTotalNum (intSize) <BR><BR>

4. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## Nope

you can do<BR><BR>dim aryTotalNum (ANumber).<BR><BR>

5. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## ALWAYS...always

use clng.<BR><BR><BR><BR>forget cint even exists.<BR><BR>

6. ... Guest

## Explain Thyself!

Would you care to explain the reason, oh mighty Mr. Akhilesh?<BR><BR>Just curious :)

7. Senior Member
Join Date
Dec 1969
Posts
3,921

## Just one reason really...

CInt() has limitations in the size of the number.<BR>CLng() does not.

8. Senior Member
Join Date
Dec 1969
Posts
10,852

## Ehh...Not exactly true.

The reason is that CInt can only handle teeny-tiny numbers. (-32,768 through 32,767) whereas CLng can handle much larger numbers. (-2,147,483,648 thrugh 2,147,483,647) Any bigger than that, and your still get an overflow error even with CLng.

9. amy
Senior Member
Join Date
Dec 1969
Posts
141

## RE: Just one reason really...

thanx! but neither CInt() nor CLng() worked for me. pls see err below. what&#039;s wrong?<BR><BR>Error Type:<BR>Microsoft VBScript compilation (0x800A0402)<BR>Expected integer constant<BR>/testpage.asp, line 255, column 19<BR>Dim aryintRecords (CLng (intTotalRecords))<BR>------------------^

10. Senior Member
Join Date
Dec 1969
Posts
3,921

## You got me...

I have never needed to test this limitation...

#### Posting Permissions

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