?
Solved

Converting String to Int in .vbs

Posted on 2011-10-11
8
Medium Priority
?
531 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:Darkejo1
8 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
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

by:David L. Hansen
ID: 36951912
0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 36951943
Try this

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

Open in new window

~bp
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Darkejo1
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

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)





0
 

Author Comment

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

Expert Comment

by:Patrick Matthews
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

by:David L. Hansen
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

by:Darkejo1
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question