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

Converting string to int

Status
Not open for further replies.

modalman

Programmer
Feb 14, 2001
156
GB
Hi, I'm reading a string from an array and need to change it into a numerical value so that I can do some calculations with it. I have used CInt() but keep getting errors. What I need is the VBScript equivalent of Javascripts' parseInt command. The code is below:

d1=CInt(Mid(dateAr(i),1,2))

The array definitely only contains numbers in its strings. Many thanks in advance ASCII silly question, get a silly ANSI
 
modalman,

HAve you tried writing out Mid(dateAr(i),1,2) first to see what this is? What does it look like? My next step would be to trim the variable.



d1=CInt( trim( Mid(dateAr(i),1,2) ) )


fengshui_1998
 
And I use CLng() by default, in case it's a large number. codestorm
Fire bad. Tree pretty. - Buffy
Hey, I'm operating on a limited mental budget here.
<insert witticism here>
 
Would it be possible that the numbers in the array only contain one digit - and you are trying to read two characters with the Mid command.

Only throwing out suggestions............. Mighty :)
 
Thanks for the comments guys. I have tried the suggestions and still get the following error:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CInt'

/timesheet/index.asp, line 88


Here is the code as it stands at the moment:

Dim d1

For i=0 To ctr-1
d1=CInt(Trim(Mid(dateAr(i),1,2)))
If IsNumeric(d1) Then Response.Write(d1 & &quot;<br>&quot;)
Next


As soon as I remove the CInt() it then works fine but then I cannot do any calculations with the string even though the IsNumeric() yields true. Head scratching stuff??
ASCII silly question, get a silly ANSI
 
Doh! Just realised I'm reading array position 0. It starts at 1 in VB doesn't it. (Too much javascript!) On the first run of the loop d1 must have been set to a Null value that obviously wouldn't act as a numerical variant.

Anyway, many thanks for all your help. ASCII silly question, get a silly ANSI
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top