Page 1 of 1

How to correct the condition?

Posted: 23 Jun 2012 07:45
by doscode
I'm finishing the script from this thread:
viewtopic.php?f=3&t=3435
After I parsed the tags, I have found IP, port, country, server type and anonymity. Sometimes the type is HTTPS which I am not interested so type is empty

Code: Select all

SET type=
. Also if the anonymity is medium or low, so it is empty

Code: Select all

SET anonymity=
. Now I want the condition, if these two variables are not empty, then save the values... This code results in incorrect effect - it prints Anonymity is "" ... which is non-sense. If anonymity is empty and type is empty, then Saving should appear.

Code: Select all

if "!type!" NEQ "HTTPS" (
  if "!anonymity!" NEQ "" (
            echo Saving...                   
  ) else echo Anonymity is "!anonymity!"
)

Type and anonymity are strings usually, because they save descriptions of the server. So is there string operator for <> equivalent?

Re: How to correct the condition?

Posted: 23 Jun 2012 07:56
by foxidrive
doscode wrote:So is there string operator for <> equivalent?


not

Re: How to correct the condition?

Posted: 23 Jun 2012 07:59
by doscode
So Should I use SET /A for boolean instead? NEQ will not work for string comparation, am I right?

Re: How to correct the condition?

Posted: 23 Jun 2012 09:43
by Squashman
You either use the IF NOT ==
Or use
IF NOT DEFINED

READ THE HELP FILE FOR THE IF COMMAND!.!

Re: How to correct the condition?

Posted: 23 Jun 2012 10:10
by doscode
Squashman wrote:You either use the IF NOT ==
Or use
IF NOT DEFINED

READ THE HELP FILE FOR THE IF COMMAND!.!


Sure I know there exists NOT keyword, but did not realize I could use it to reverse operator!!!!

Thanks!

Re: How to correct the condition?

Posted: 23 Jun 2012 11:52
by Squashman
What did you think it was used for?

If you want to do something when a variable has something assigned to it then use IF DEFINED

Re: How to correct the condition?

Posted: 24 Jun 2012 07:55
by doscode
Squashman wrote:What did you think it was used for?


For EXIST and DEFINED

Re: How to correct the condition?

Posted: 24 Jun 2012 08:02
by Squashman
doscode wrote:
Squashman wrote:What did you think it was used for?
and DEFINED

So you basically answered your own question.

Re: How to correct the condition?

Posted: 25 Jun 2012 00:11
by doscode
Squashman wrote:So you basically answered your own question.


Not me, but you. foxidrive answered two, but I did not understand his answer which was too short.

Re: How to correct the condition?

Posted: 25 Jun 2012 00:22
by Ed Dyreen
doscode wrote:... NEQ will not work for string comparation, am I right?
No, you are wrong.

Code: Select all

if "string" neq "bra" echo.it works ;)