Link to home
Start Free TrialLog in
Avatar of Darkejo1
Darkejo1

asked on

Converting String to Int in .vbs

I'm somewhat new to the coding world so bare with me...

newDate=Split(date,"/")
Integer=newDate(1) + 1

Open in new window


Since today is the 11th, the "integer" variable should read as 12. I've tried to convert the string to an integer with newDate=CInt(Integer), but was unsuccessful. What am I doing wrong here?
Avatar of David L. Hansen
David L. Hansen
Flag of United States of America image

Can you post more of your code?  Most importantly, please show where and how your variables (newDate and Integer) are declared.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Darkejo1
Darkejo1

ASKER

Sure. Date was never declared. I'm going to assume it's a system variable. I'm not even allowed to redefine date.

Dim newDate
Dim Integer
newDate=Split(date,"/")
Integer=newDate(1) + 1
Response.write date
Response.write newDate(1)
Response.write newDate(1) + 1

Open in new window


This is what i get when I run it...

10/11/2011
11
11 (This is where I should get 11)





Oops, Should get 12 from the output of line 7..
If you always want to get tomorrow's day number:


MyResult = Day(Date + 1)


The Day function already returns a Long.  If it must be an Int:


MyResult = CInt(Day(Date + 1))
The variable "Integer" I'm sure will cause problems eventually, I suggest changing it to something more descriptive.  At any rate the word "Integer" is usually a reserved word in most programming languages and as such should be avoided as a variable name.
Thanks, Sl8rz. I found that out when trying to assign Integer. I didn't use that in my code, I was just using that for demonstrative purposes and testing.