Jump to content

Combining And And Or Operators


Recommended Posts

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

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

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

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

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

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