?
Solved

How do I compare numbers in VBscript

Posted on 2010-09-01
9
Medium Priority
?
1,028 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:SyFy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 18

Accepted Solution

by:
exx1976 earned 500 total points
ID: 33578907
If all you want is to know if today is the last day of the month...
If Month(Now) <> Month(Now + 1) Then WScript.Echo "Today is the last day of the month"

Open in new window

0
 
LVL 10

Assisted Solution

by:ALaRiva
ALaRiva earned 500 total points
ID: 33578911
Just off the top, try:
If Tomorrow < Today  Then Wscript.Echo ("End Of Month")

End of the Month is a string, so you would need to enclose it in quotes, unless it were a variable, but seeing the spaces, I'm assuming that it was supposed to be a string since you can't have spaces in variables.

- Anthony
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 33579120
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

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!

 
LVL 18

Expert Comment

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


LOL
0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 33579203
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
0
 
LVL 6

Expert Comment

by:Alan Gunn
ID: 33579321
Hi exx1976.
I liked your line of code and I have added it to the "Snippets" on my VBSedit. :-)
 
0
 

Author Comment

by:SyFy
ID: 33579378
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
0
 
LVL 18

Expert Comment

by:exx1976
ID: 33579415
Set oWS = CreateObject("WScript.Shell")
oWS.Run("c:\run.bat")


I'd just convert the bat commands into VBS though, personally..
0
 

Author Closing Comment

by:SyFy
ID: 33579573
Thanks everyone !
0

Featured Post

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!

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 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