Jump to content

AutoIt, VBScript and Options Command


FSTrent
 Share

Recommended Posts

Hello,

I am working an autoit application that runs in vbscript.

Everything works fine with the script, except when I try to access the SetOption commands.

Set oShell = WScript.CreateObject("WScript.Shell")

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

oAutoIt.AutoItSetOption('WinTitleMatchMode', '2')

oAutoIt.SetOption('WinTitleMatchMode', 2)

oAutoIt.AutoItSetOption("SendKeyDelay", 500)

Can anyone help me with the correct syntax to set these options via vbscript? Apparently neither oAutoIt.AutoItSetOption or oAutoIt.SetOption work as intended. Is this something thats not possible while using vbscript and autoit?

FSTrent

Link to comment
Share on other sites

This is a modified version of the example in the autoitx help file:

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
oAutoIt.Opt("WinTitleMatchMode", 2)
Thank you for your quick reply.

I get an error message when I try to run what you suggested. I tried several things that are similiar trying to get around the 'Cannot use parentheses when calling a sub' issue. Any other thoughts? This is a short test script.

Dim tempstring
    Set oShell = WScript.CreateObject("WScript.Shell")
    Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

    oAutoIt.Run("notepad.exe")
    oAutoIt.WinMinimizeAll()
    oAutoIt.WinActivate("Untitled - Notepad")
'   oAutoIt.Opt("WinTitleMatchMode", 2)
' Error - Cannot Use Parentheses when calling a sub

'   oAutoIt.Opt('WinTitleMatchMode', 2)
' Error Invalid Syntax

'   tempstring = Chr(34) & "WinTitleMatchMode" & Chr(34) & ", 2"
'   MsgBox(tempstring)
'   oAutoIt.Opt(tempstring)
' Error - Wrong number of arguments or invalid property assignment: 'oAutoIt.Opt'

    tempstring = Chr(34) & "WinTitleMatchMode" & Chr(34) & ", 2"
    MsgBox(tempstring)
'   oAutoIt.AutoItSetOption(tempstring)
' Error - Wrong number of arguments or invalid property assignment: 'oAutoIt.Opt'
'   oAutoIt.SetOption(tempstring)
' Error Object doesn't support this property or method: 'oAutoIt.SetOption'
    oAutoIt.Opt(tempstring)
' Error - Wrong number of arguments or invalid property assignment: 'oAutoIt.Opt'
Edited by FSTrent
Link to comment
Share on other sites

That 'Cannot use parentheses when calling a sub' issue is not AutoIt related. If your function does not set something to itself prior to returning in VBScript, it's considered a Sub. Meaning, this will be considered a sub.

Function MyFunction(var1,var2)

dim var3

var3 = var1 + var2

End Function

Whereas this will be treated as a function, and not generate the error:

Function MyFunction(var1,var2)

MyFunction = var1 + var2

End Function

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

SO, the answer to you problem might be invoking it this way:

oAutoIt.Opt "WinTitleMatchMode", 2

WithOUT the parenthesis.

lol self taught vbscript for the lose. I have been stumbling with that particular type of error forever. Thanks for the help. Works perfectly.

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