Jump to content

Can anyone help me please?


Recommended Posts

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
~~~~~~~~~~~~~~~~^
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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

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

Monkey's are, like, natures humans.

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