Solved

# Converting String to Int in .vbs

Posted on 2011-10-11
Medium Priority
531 Views
I'm somewhat new to the coding world so bare with me...

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

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?
0
Question by:Darkejo1

LVL 15

Expert Comment

ID: 36951897
Can you post more of your code?  Most importantly, please show where and how your variables (newDate and Integer) are declared.
0

LVL 15

Expert Comment

ID: 36951912
0

LVL 59

Accepted Solution

Bill Prew earned 2000 total points
ID: 36951943
Try this

``````newDate=Split(date,"/")
Integer=CInt(newDate(1)) + 1
``````
~bp
0

Author Comment

ID: 36951946
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
``````

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

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

0

Author Comment

ID: 36951951
Oops, Should get 12 from the output of line 7..
0

LVL 93

Expert Comment

ID: 36951979
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))
0

LVL 15

Expert Comment

ID: 36951995
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.
0

Author Comment

ID: 36952007
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.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
###### Suggested Courses
Course of the Month14 days, 19 hours left to enroll