Sy Fy
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
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 )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Really? No one likes my one line of code that accomplishes the same thing? :(
LOL
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
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. :-)
I liked your line of code and I have added it to the "Snippets" on my VBSedit. :-)
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
I tried using "call c:\run.bat" after the IF statement but got an error.
Thanks
SyFy
Set oWS = CreateObject("WScript.Shel l")
oWS.Run("c:\run.bat")
I'd just convert the bat commands into VBS though, personally..
oWS.Run("c:\run.bat")
I'd just convert the bat commands into VBS though, personally..
ASKER
Thanks everyone !
try this code - modified slightly to reduce some additional logic.
Open in new window