![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||