Jump to content

Use comparison operators in variables in VBScript


Recommended Posts

In the following VBScript code I'm trying to compare two numbers and pass the operator from the command line. I substitute the words "greater", "less" and "equal" instead of the symbols to not upset the shell. However the If..Then statement doesn't like me using the variable for the operator. Any ideas. Thanks for the help.

Set objShell = WScript.CreateObject("WScript.Shell")
Set colArgs = WScript.Arguments

str1stnumber = colArgs.Item(0)
str2ndnumber = colArgs.Item(1)
strOperator = colArgs.Item(2)


If strOperator = "less" Then
   strOperator = "<"
ElseIf strOperator = "greater" Then
   strOperator = ">"
ElseIf strOperator = "equal" Then
   strOperator = "="
End If


If str1stnumber strOperator str2ndnumber Then
   wscript.echo "it works"
End If

Link to comment
Share on other sites


maybe this is an option ?

gr /\/\o\/\/

If strOperator = "greater" AND str1stnumber < str2ndnumber Then

wscript.echo "it works greater"

ElseIf strOperator = "less" AND str1stnumber > str2ndnumber Then

wscript.echo "it works less"

ElseIf strOperator = "equal" AND str1stnumber = str2ndnumber Then

wscript.echo "it works equal"

endif

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...