Link to home
Start Free TrialLog in
Avatar of Sy Fy
Sy FyFlag for United States of America

asked on

How do I compare numbers in VBscript

All,

I am not a programmer and I did find the following code from here which I modified a little.
I am using the script to calculate if it's the last day of the month.   When I run the script without
the IF statement I can display today's day for example 31 and tommrow 01.  But when I compare with the IF statement I don't get the results.

Thanks
' Calculate tomorrow's date
dtmTomorrow = DateAdd("d",1,Date)

' Get tomorrow's day, add leading zero if necessary
If DatePart("d",dtmTomorrow) < 10 Then
	Tomorrow = 0 & DatePart("d",dtmTomorrow)
Else
	Tomorrow = DatePart("d",dtmTomorrow)
End If

' Format output for tomorrow
strTomor = "Tomorrow:   " & Tomorrow &"  "

 
' Get current day, add leading zero if necessary
If DatePart("d",Date) < 10 Then
	Today = 0 & DatePart("d",Date)
Else
	Today = DatePart("d",Date)
End If

' Format output for today
strToday = "Today:      " & Today _
         & "  " & vbCrLf

' Display the result
if Tomorrow < Today  then Wscript.Echo ( End Of Month )

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of exx1976
exx1976
Flag of United States of America image

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
SOLUTION
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 sirbounty
I think it has to do with your trailing line feed...
try this code - modified slightly to reduce some additional logic.
' Calculate tomorrow's date
dtmTomorrow = DateAdd("d",1,Date)

' Get tomorrow's day, add leading zero if necessary
Tomorrow = Right("0" & DatePart("d",dtmTomorrow),2)

' Format output for tomorrow
strTomor = "Tomorrow:   " & Tomorrow & "  "

 
' Get current day, add leading zero if necessary
Today = Right("0" & DatePart("d",Date),2)

' Format output for today
strToday = "Today:      " & Today & "  "

' Display the result
if Tomorrow < Today  then Wscript.Echo " End Of Month "

Open in new window

Really?  No one likes my one line of code that accomplishes the same thing?  :(


LOL
exx1976,
I assumed the user needed the other variables for future use, or because he is learning the code, and something with more options and more learning would be of benefit to him.

Your line does it quickly, I just assumed he wanted the other values for future use.

- Anthony
Hi exx1976.
I liked your line of code and I have added it to the "Snippets" on my VBSedit. :-)
 
Avatar of Sy Fy

ASKER

Thanks guys,  I am new to programming so both options are really great for learning . Now that we can determine if it's the last day of the month,  what would be the code to run a batch file from this VBscript.
I tried using "call c:\run.bat"  after the IF statement but got an error.

Thanks
SyFy
Set oWS = CreateObject("WScript.Shell")
oWS.Run("c:\run.bat")


I'd just convert the bat commands into VBS though, personally..
Avatar of Sy Fy

ASKER

Thanks everyone !