Sign in to follow this  
Followers 0
Yokho

Problem with operator "And" in a script line

8 posts in this topic

Hello, so here's my problem;

I am trying to compare 4 variables, 2 sets of them (var1 vs var2, and var3 vs var4)

Here's my actual line:

If $var1 <> $var2 And $var3 <> $var4 then

MsgBox(4, "title", "select yes if the informations need adjusting")

EndIf

Now , my problem is, i only want the message box to pop up when var1 isnt like var2, AND var3 isnt like var4, but at the moment, as soon as 1 of the 2 sets isnt matching, the message box pops up. Anyone know why? I am pretty new to programming so i might be missing something obvious, but i thought that the AND i put there would make the pop up window pop ONLY if BOTH sets of variables were different ( I tried ($var1 <> $var2) And ($var3 <> $var4) then, and also tried ($var1 <> $var2 And $var3 <> $var4) then, but neither worked) Also, when both variable sets are matching, the pop up window doesn't pop, as intended.

Anyone got any clue as to what im doing wrong?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello, so here's my problem;

I am trying to compare 4 variables, 2 sets of them (var1 vs var2, and var3 vs var4)

Here's my actual line:

If $var1 <> $var2 And $var3 <> $var4 then

MsgBox(4, "title", "select yes if the informations need adjusting")

EndIf

Now , my problem is, i only want the message box to pop up when var1 isnt like var2, AND var3 isnt like var4, but at the moment, as soon as 1 of the 2 sets isnt matching, the message box pops up. Anyone know why? I am pretty new to programming so i might be missing something obvious, but i thought that the AND i put there would make the pop up window pop ONLY if BOTH sets of variables were different ( I tried ($var1 <> $var2) And ($var3 <> $var4) then, and also tried ($var1 <> $var2 And $var3 <> $var4) then, but neither worked) Also, when both variable sets are matching, the pop up window doesn't pop, as intended.

Anyone got any clue as to what im doing wrong?

If statement is correct .... WHat are the values of the 4 variables when it isn't working ?

Important to tell us if they are strings or Numbers ....

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

1

Welcome to Autoit

2

Works for me

$var1 = 2
$var2 = 1
$var3 = 1
$var4 = 1


If $var1 <> $var2 And $var3 <> $var4 then
MsgBox(4, "title 1", "select yes if the informations need adjusting")
EndIf

$var1 = 1
$var2 = 1
$var3 = 2
$var4 = 1


If $var1 <> $var2 And $var3 <> $var4 then
MsgBox(4, "title 2", "select yes if the informations need adjusting")
EndIf

$var1 = 2
$var2 = 1
$var3 = 2
$var4 = 1


If $var1 <> $var2 And $var3 <> $var4 then
MsgBox(4, "title 3", "select yes if the informations need adjusting")
EndIf

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

1

Welcome to Autoit

2

Works for me

$var1 = 2
$var2 = 1
$var3 = 1
$var4 = 1
If $var1 <> $var2 And $var3 <> $var4 then
MsgBox(4, "title 1", "select yes if the informations need adjusting")
EndIf

$var1 = 1
$var2 = 1
$var3 = 2
$var4 = 1
If $var1 <> $var2 And $var3 <> $var4 then
MsgBox(4, "title 2", "select yes if the informations need adjusting")
EndIf

$var1 = 2
$var2 = 1
$var3 = 2
$var4 = 1
If $var1 <> $var2 And $var3 <> $var4 then
MsgBox(4, "title 3", "select yes if the informations need adjusting")
EndIf

8)

Alrighty, My values are strings, and when the script doesn't work, its because only one of the sets don't match, while i want the window to pop only if BOTH dont match. Hope that helps.

Share this post


Link to post
Share on other sites

Alrighty, My values are strings, and when the script doesn't work, its because only one of the sets don't match, while i want the window to pop only if BOTH dont match. Hope that helps.

The If you posted will ONLY be true when both sets are not equal...

Give us an example of values that have the problem .....


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The only thing I can think of is if Yokho wants to do a case-sensitive comparision.

In that case, of course, the required code would be

If (Not ($var1 == $var2)) And (Not ($var3 == $var4)) Then


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Hi ppl, Yokho is actually a cow-worker of mine and I found out the problem with him. Being new to programming he forgot to check his strings for extra spaces " " :o

Thanks for the replies !

Share this post


Link to post
Share on other sites

The only thing I can think of is if Yokho wants to do a case-sensitive comparision.

In that case, of course, the required code would be

If (Not ($var1 == $var2)) And (Not ($var3 == $var4)) Then

*ashamed* Argh... i'm sorry guys, in fact, there was a problem with the compilation of one of my values, it had a space that wasn't supposed to be there, which made the first set always different. :o That'll teach me to not look character by character when i do my debug tests ><

Sorry! And thanks for the support, it helped me with another problem i was having with the case sensitive problem!

Share this post


Link to post
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
Sign in to follow this  
Followers 0