Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - A little math

Reply
 
Old 03-09-2009   #1 (permalink)
keith


 
 

A little math

I am trying to write a vbscript that does some basic math. I want to
be able to input a number and let the logic in the script tell me if
the number is zero, less than one thousand, or greater than or equal
to one thousand. The script I have written to do this is below:

'*************************Getting the file system
object*************************
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strComputer = "."

IntGrpMembers = InputBox ("Enter a number.")


If IntGrpMembers ="0" Then

Wscript.echo IntGrpMembers & " is equal to zero." &VbCrLf

ElseIf IntGrpMembers <"1000" Then

Wscript.echo IntGrpMembers & " is less than one thousand." &VbCrLf

ElseIf IntGrpMembers >="1000" Then

Wscript.echo IntGrpMembers & " is greater than or equal to 1000."
&VbCrLf

else

Wscript.echo IntGrpMembers & " did not fall with in the expected
criteria." &VbCrLf

End IF

The problem I found is that my logic isn’t working quite like I
thought it would. When I run the script and I input a value of 2 I
get back, “2 is greater than or equal to 1000.” That’s just not
right. Will someone please help me figure out what I am doing wrong.

Thanks,

Keith

My System SpecsSystem Spec
Old 03-09-2009   #2 (permalink)
T Lavedas


 
 

Re: A little math

On Mar 9, 10:06*am, keith <keith...@xxxxxx> wrote:
Quote:

> I am trying to write a vbscript that does some basic math. *I want to
> be able to input a number and let the logic in the script tell me if
> the number is zero, less than one thousand, or greater than or equal
> to one thousand. *The script I have written to do this is below:
>
> '*************************Getting the file system
> object*************************
> Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
> Set objShell = CreateObject("WScript.Shell")
> strComputer = "."
>
> IntGrpMembers = InputBox ("Enter a number.")
>
> If IntGrpMembers ="0" Then
>
> * * * * Wscript.echo IntGrpMembers & " is equal to zero." &VbCrLf
>
> ElseIf IntGrpMembers <"1000" Then
>
> * * * * Wscript.echo IntGrpMembers & " is less than one thousand." &VbCrLf
>
> ElseIf IntGrpMembers >="1000" Then
>
> * * * * Wscript.echo IntGrpMembers & " is greater than or equal to 1000."
> &VbCrLf
>
> else
>
> * * * * Wscript.echo IntGrpMembers & " did not fall with in the expected
> criteria." &VbCrLf
>
> End IF
>
> The problem I found is that my logic isn’t working quite like I
> thought it would. *When I run the script and I input a value of 2 I
> get back, “2 is greater than or equal to 1000.” That’s just not
> right. *Will someone please help me figure out what I am doing wrong.
>
> Thanks,
>
> Keith
Your logic is making string comparisons. In such cases the result is
more akin to sorting, where "2" will come after "1000" - that is, it's
greater than "1000".

Just remove the quotes around the literal constants in the IF
statements and it should work fine. Well, there is one more thing -
change your input line to force the result to be numeric. One way is
to add zero to it (the inelegant way I normally use). Or use the more
elegant ...

IntGrpMembers = CSng(InputBox ("Enter a number."))

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
My System SpecsSystem Spec
Old 03-09-2009   #3 (permalink)
Alex K. Angelopoulos


 
 

Re: A little math

Expanding on Tom's response a bit, you want to change ALL your numeric
lookups to integer values, and force them where necessary. Specifically, I
would use the following for the IntGrpMembers entry:

IntGrpMembers = CInt(InputBox ("Enter a number."))

If you don't do this, whatever is entered into the inputbox will be
interpreted as a string by default.

"keith" <keithlr2@xxxxxx> wrote in message
news:873edcc5-2390-4474-8387-884d2b77f601@xxxxxx
Quote:

> I am trying to write a vbscript that does some basic math. I want to
> be able to input a number and let the logic in the script tell me if
> the number is zero, less than one thousand, or greater than or equal
> to one thousand. The script I have written to do this is below:
>
> '*************************Getting the file system
> object*************************
> Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
> Set objShell = CreateObject("WScript.Shell")
> strComputer = "."
>
> IntGrpMembers = InputBox ("Enter a number.")
>
>
> If IntGrpMembers ="0" Then
>
> Wscript.echo IntGrpMembers & " is equal to zero." &VbCrLf
>
> ElseIf IntGrpMembers <"1000" Then
>
> Wscript.echo IntGrpMembers & " is less than one thousand." &VbCrLf
>
> ElseIf IntGrpMembers >="1000" Then
>
> Wscript.echo IntGrpMembers & " is greater than or equal to 1000."
> &VbCrLf
>
> else
>
> Wscript.echo IntGrpMembers & " did not fall with in the expected
> criteria." &VbCrLf
>
> End IF
>
> The problem I found is that my logic isn’t working quite like I
> thought it would. When I run the script and I input a value of 2 I
> get back, “2 is greater than or equal to 1000.” That’s just not
> right. Will someone please help me figure out what I am doing wrong.
>
> Thanks,
>
> Keith
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Math beyond double precision .NET General
math 3.0 keeps losing activation code Vista General
Lets do the math!!! :-) Vista General
Doing math on functions PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46