Sign in to follow this  
Followers 0
williamray507

Can anyone help me please?

5 posts in this topic

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



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 (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

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

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
1 person likes this

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  
Followers 0