How to correct the condition?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
doscode
Posts: 175
Joined: 15 Feb 2012 14:02

How to correct the condition?

#1 Post by doscode » 23 Jun 2012 07:45

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to correct the condition?

#2 Post by foxidrive » 23 Jun 2012 07:56

doscode wrote:So is there string operator for <> equivalent?


not

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: How to correct the condition?

#3 Post by doscode » 23 Jun 2012 07:59

So Should I use SET /A for boolean instead? NEQ will not work for string comparation, am I right?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How to correct the condition?

#4 Post by Squashman » 23 Jun 2012 09:43

You either use the IF NOT ==
Or use
IF NOT DEFINED

READ THE HELP FILE FOR THE IF COMMAND!.!

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: How to correct the condition?

#5 Post by doscode » 23 Jun 2012 10:10

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!

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How to correct the condition?

#6 Post by Squashman » 23 Jun 2012 11:52

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

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: How to correct the condition?

#7 Post by doscode » 24 Jun 2012 07:55

Squashman wrote:What did you think it was used for?


For EXIST and DEFINED

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How to correct the condition?

#8 Post by Squashman » 24 Jun 2012 08:02

doscode wrote:
Squashman wrote:What did you think it was used for?
and DEFINED

So you basically answered your own question.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: How to correct the condition?

#9 Post by doscode » 25 Jun 2012 00:11

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.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: How to correct the condition?

#10 Post by Ed Dyreen » 25 Jun 2012 00:22

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 ;)

Post Reply