Jump to content

Problem with operator "And" in a script line


Recommended Posts

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?

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Link to comment
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.
Link to comment
Share on other sites

  • Developers

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 .....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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!

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
 Share

  • Recently Browsing   0 members

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