Jump to content
Sign in to follow this  
williamray507

Can anyone help me please?

Recommended Posts

williamray507

Ok so I am trying to set 2 variables in my script, the first one is $var1 and it gets that from the clipboard then the second $var2 grabs the first 4 characters from the first one and then I want to do one of two things based on that variable but it isn’t working. if I leave it as it is below then the Syntax Check passes but they don't do what it is supposed to do. Any help would be great.

$var1 = ClipGet ()
$var2 = StringLeft ( $var1, 4 )

If $var2 = "BOB1" or "BOB2" or "BOB3" Then
    MsgBox ( 0, "It is Bob", "It is Bob" )
Else
    MsgBox ( 0, "Not Bob", "Not Bob" )
EndIf

If have it like this then it errors out:

$var1 = ClipGet ()
$var2 = StringLeft ( $var1, 4 )

If $var2 = BOB1 or BOB2 or BOB3 Then
    MsgBox ( 0, "It is Bob", "It is Bob" )
Else
    MsgBox ( 0, "Not Bob", "Not Bob" )
EndIf

ERROR: syntax error
If $var2 = BOB1 or
~~~~~~~~~~~~~~~~^

Share this post


Link to post
Share on other sites
water

You have to write it this way:

$var1 = ClipGet()
$var2 = StringLeft($var1, 4)

If $var2 = "BOB1" or $var2 = "BOB2" or $var2 = "BOB3" Then
    MsgBox(0, "It is Bob", "It is Bob" )
Else
    MsgBox(0, "Not Bob", "Not Bob" )
EndIf


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
dv8

The code in your fist example works fine.

Note that in order for your IF to succeed, the content in your clipboard needs to match not only the characters but their case as well.

So if you have "bob1 bla bla" in the clipboard, the IF check will fail.

If you have "BOB1 bla bla" in the clipboard, the IF check will succeed.

EDIT: WATER is right. I tested only with BOB1 and it worked for me... But my notes are still true...

Edited by dv8

Share this post


Link to post
Share on other sites
williamray507

You have to write it this way:

$var1 = ClipGet()
$var2 = StringLeft($var1, 4)

If $var2 = "BOB1" or $var2 = "BOB2" or $var2 = "BOB3" Then
    MsgBox(0, "It is Bob", "It is Bob" )
Else
    MsgBox(0, "Not Bob", "Not Bob" )
EndIf

The code in your fist example works fine.

Note that in order for your IF to succeed, the content in your clipboard needs to match not only the characters but their case as well.

So if you have "bob1 bla bla" in the clipboard, the IF check will fail.

If you have "BOB1 bla bla" in the clipboard, the IF check will succeed.

EDIT: WATER is right. I tested only with BOB1 and it worked for me... But my notes are still true...

Thank you both for your help. It is now working the way I want it to. And dv8 thanks for the heads up on the case of the characters, I did not know that either.

Thanks,

Bill

Share this post


Link to post
Share on other sites
JohnOne

You could also write it like this.

$var1 = ClipGet()
$var2 = StringLeft($var1, 4)
Switch $var2
    Case "BOB1", "BOB2", "BOB3"
        MsgBox(0, "It is Bob", "It is Bob" )
    Case Else
        MsgBox(0, "Not Bob", "Not Bob" )
EndSwitch
  • Like 1

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  

×