Sign in to follow this  
Followers 0
the_lord_mephy

If statement not working

12 posts in this topic

I have this code:

If Not @DesktopHeight = "600" and not @DesktopWidth = "800" Then
   MsgBox(0, "Error", "Please set your desktop height to 600 and your desktop width to 800. Then restart the program")
   Exit
EndIf

I tried setting my desktop width and height to 768x1024 but the msgbox doesn't execute and the program continues to run. Please help me.


My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe this will help:

If Not( (@DesktopHeight = "600") and (@DesktopWidth = "800") ) Then
  MsgBox(0, "Error", "Please set your desktop height to 600 and your desktop width to 800. Then restart the program")
  Exit
EndIf

*** Matt @ MPCS

EDIT: Larry is quick today

Edited by Matt @ MPCS

Share this post


Link to post
Share on other sites

thanks guys


My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

try this:

tooltip(@DesktopHeight&"x"&@DesktopWidth,0,0)
If @DesktopHeight<>600 and @DesktopWidth<>800 Then
  MsgBox(1, "Error", "Please set your desktop height to 600 and your desktop width to 800. Then restart the program")
  Exit
EndIf
sleep(1000)

I like the tooltip and sleep to show what yours is for debug.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Ooh I like that, Thanks script kiddy. Good idea :)


My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

:) Beware of AND-ing negative expressions .. ie <>, or "not equal"

Matt's suggestion will give the desired results ..

If Not( (@DesktopHeight = "600") and (@DesktopWidth = "800") ) Then

.. But to simplify it by using negative expressions, you need to change AND to OR ;) . So this is not equivalent:

If @DesktopHeight<>600 and @DesktopWidth<>800 Then

But this will give you the same results:

If @DesktopHeight<>600 or @DesktopWidth<>800 Then

Hope this helps

:)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@trids, You have a good point but I don't know if your example is valid. When reading the first example:

If @DesktopHeight<>600 and @DesktopWidth<>800 Then

Logically it reads:

If the desktop height is less than or greater than 600 AND the desktop width is less than or greater than 800 then <execute following code>

That says that both the height and width cannot be equal to 600 or 800 respectivly.

While your second example reads:

If @DesktopHeight<>600 or @DesktopWidth<>800 Then

Logically it reads:

If the desktop height is less than or greater than 600 OR the desktop width is less than or greater than 800 then <execute following code>

Which means that if either the width=800 or the height=600 the code will be executed.

Technically I believe you are incorrect in your statement, the correct comparison would require that both the height and width not equal their respective values, therefore the correct code would be:

If @DesktopHeight<>600 and @DesktopWidth<>800 Then

Of course in this situation it makes absolutly no difference which is used because we are working with monitor resolution that would always have a width of 800 if the height is 600 (true only when using standard video cards).

I apologize if I am incorrect here but this logic makes sense to me that is why I am posting this correction.

*** Matt @ MPCS

ADDITION: This proves Larry's solution correct also.

Edited by Matt @ MPCS

Share this post


Link to post
Share on other sites

Try the following example if you don't believe me:

If 1<>1 And 1<>2 Then
   MsgBox(0,"","Exp[b][/b]ression is true")
EndIf

Result: No MsgBox Shown

If 1<>1 Or 1<>2 Then
   MsgBox(0,"","Exp[b][/b]ression is true")
EndIf

Result: MsgBox Shown

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I stand corrected... I failed to dumb down my approach:

If Not( (@DesktopHeight = "600") and (@DesktopWidth = "800") ) Then

You are absolutly correct. Examples:

If Not((1=1) Or (1=2)) Then
   MsgBox(0,"","Exp[b][/b]ression is true")
EndIf

Result: No messagebox shown

If Not((1=1) And (1=2)) Then
   MsgBox(0,"","Exp[b][/b]ression is true")
EndIf

Result: Messagebox shown

Addition: This proves Larry's answer to be better than mine though:

If @DesktopHeight <> 600 And @DesktopWidth <> 800 Then

*** Matt @ MPCS

Edited by Matt @ MPCS

Share this post


Link to post
Share on other sites

Of course in this situation it makes absolutly no difference which is used because we are working with monitor resolution that would always have a width of 800 if the height is 600 (true only when using standard video cards).

<{POST_SNAPBACK}>

.. that's true, but your orginal code is a closer match with the intruction to the user "Please set your desktop height to 600 and your desktop width to 800. Then restart the program".

Bottom line is: you want the screen to be at 600 x 800 .. and if it's not, then send the message.

=> In other words: if there is anything wrong with the resolution, send the message.

=> In other words: if height is wrong OR width is wrong, send the message.

=> In other words: If @DesktopHeight<>600 OR @DesktopWidth<>800, send the message.

I'm not basing my position on video cards, but on pure Boolean logic. And the only reason I mentioned you at all is that yours was correct .. other than that, it makes no difference to me whose solution is correct or wrong

:)

Share this post


Link to post
Share on other sites

I'm not basing my position on video cards, but on pure Boolean logic. And the only reason I mentioned you at all is that yours was correct .. other than that, it makes no difference to me whose solution is correct or wrong

I know that, I was just trying to prove to myself that I could still think through boolean logic logically and failed miserably. Thanks for your compliment, but my code is actually incorrect... Larry's is better.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites
:) .. that's ok - it's easy to tie yourself in kNOTs when reading Boolean logic from an American English point of view!

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