Sign in to follow this  
Followers 0
Pieter

Combining And And Or Operators

6 posts in this topic

#1 ·  Posted (edited)

I want to check if the clipboard contains a URL containing an image. This is what I want the script to do: check if the string contains both "http://" and a valid image extension such as .jpg or .bmp. This is the code I used to let the script figure this out:

$clipbrdstring = ClipGet()
If StringInStr($clipbrdstring, "http://") = 1 And StringInStr($clipbrdstring, ".jpg") = 1 Or StringInStr($clipbrdstring, ".bmp") = 1 Or StringInStr($clipbrdstring, ".gif") = 1 Then
GUICtrlSetData( $PhotoDownloadURL, ClipGet())
EndIf
I tried it, but it doesn't work the way it should. What's wrong with this piece of code? Is there something wrong with the way I combined the And and Or operators?

Edited by Pieter

iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites



I want to check if the clipboard contains a URL containing an image. This is what I want the script to do: check if the string contains both "http://" and a valid image extension such as .jpg or .bmp. This is the code I used to let the script figure this out:

$clipbrdstring = ClipGet()
If StringInStr($clipbrdstring, "http://") = 1 And StringInStr($clipbrdstring, ".jpg") = 1 Or StringInStr($clipbrdstring, ".bmp") = 1 Or StringInStr($clipbrdstring, ".gif") = 1 Then
GUICtrlSetData( $PhotoDownloadURL, ClipGet())
EndIf
I tried it, but it doesn't work the way it should. What's wrong with this piece of code? Is there something wrong with the way I combined the And and Or operators?
well, you should read autoit help, in page refered to boolean values. The script could be...

$clipbrdstring = ClipGet()

Select
Case StringInStr($clipbrdstring, "http://")
    If StringInStr($clipbrdstring, ".jpg") Or StringInStr($clipbrdstring, ".bmp") Or StringInStr($clipbrdstring, ".gif") Then
        GUICtrlSetData( $PhotoDownloadURL, ClipGet())
    EndIf
Case Else
    $clipbrdstring=0;to free memory
EndSelect

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It's buried, but the docs contain a list of the predecence of operations. Like other languages, AND has higher precedence than OR.

Your expression is evaluated as follows:

IF (h AND j) OR b OR g

Instead you want to add explicit parentheses:

IF h AND (j OR b OR g)

Hope that helps

Edited by CyberSlug

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

#4 ·  Posted (edited)

It doesn't. Sorry. I tried

If StringInStr($clipbrdstring, "http://") = 1 And (StringInStr($clipbrdstring, ".jpg") = 1 Or StringInStr($clipbrdstring, ".bmp") = 1 Or StringInStr($clipbrdstring, ".gif") = 1) Then
  GUICtrlSetData( $PhotoDownloadURL, $clipbrdstring)
EndIf

Edited by Pieter

iPod + Online calendars = iPodCALsync

Share this post


Link to post
Share on other sites

Try this:

ClipPut('http:// .gif')

$clipbrdstring = ClipGet()

If StringInStr($clipbrdstring, "http://") And _
    ( StringInStr($clipbrdstring, ".jpg") Or _
    StringInStr($clipbrdstring, ".bmp") Or _
    StringInStr($clipbrdstring, ".gif") ) Then
  MsgBox(0, '', $clipbrdstring)
EndIf

:think:

Share this post


Link to post
Share on other sites

Yup, that works.


iPod + Online calendars = iPodCALsync

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