Jump to content

AutoItX with VB6


bigred
 Share

Recommended Posts

To do

1) Download the aix dll from this site

2) register the dll using regsvr32.exe

3) Open a new project in VB6.

4) add the following line in general section

Dim cAutoit As New AUTOITX3Lib.AutoItX3

Once declared as above, you can use any autoit function as below:

dim intResult as integer

intResult = cAutoit.WinExists("window title","widnow text")

If intResult = 0 Then
    --- do what you want
endif

Hope, this clarifies. The help file for the AutoITX describes the functions/methods that you can use with the DLL. You can not use all autoit functions ( as like autoit3.exe ) but most of them.

Link to comment
Share on other sites

Great, thanks for the help!

Ok so that code you wrote is what I have to use every time right? I use that, then enter in the AIX commands that I want to execute in the area you specified. Also where do I enter "Dim cAutoit As New AUTOITX3Lib.AutoItX3". Im not sure where my "general" area is. So far I only have Private Subroutines.

Link to comment
Share on other sites

Great, thanks for the help!

Ok so that code you wrote is what I have to use every time right?  I use that, then enter in the AIX commands that I want to execute in the area you specified.  Also where do I enter "Dim cAutoit As New AUTOITX3Lib.AutoItX3".  Im not sure where my "general" area is.  So far I only have Private Subroutines.

<{POST_SNAPBACK}>

Declare the autoitx3lib.autoitx in General Declarations.

In VB, when you are in the code area, click on the combo boxes at top ( Example: Form on the left side and load on the right side. You click the combo box containing Form -> choose General. VB will automatically set the right side combo box as Declarations )

Link to comment
Share on other sites

How's this?

Dim AIX As New AUTOITX3Lib.AutoItX3

Private Sub Start_Click()
Status1.Text = Status1.Text & vbNewLine & "TSM has started"
    Dim intResult As Integer
    intResult = AIX.WinExists("Untitled -")
    If intResult = 0 Then
        AIX.MouseClick "left", 455, 520, 2
    End If
End Sub

Private Sub Stop_Click()
Status1.Text = Status1.Text & vbNewLine & "TSM has stoped"
End Sub
Link to comment
Share on other sites

How's this?

Dim AIX As New AUTOITX3Lib.AutoItX3

Private Sub Start_Click()
Status1.Text = Status1.Text & vbNewLine & "TSM has started"
    Dim intResult As Integer
    intResult = AIX.WinExists("Untitled -")
    If intResult = 0 Then
        AIX.MouseClick "left", 455, 520, 2
    End If
End Sub

Private Sub Stop_Click()
Status1.Text = Status1.Text & vbNewLine & "TSM has stoped"
End Sub

<{POST_SNAPBACK}>

I don't see any problem in the code. You can use methods without () also.
Link to comment
Share on other sites

I don't see any problem in the code. You can use methods without () also.

<{POST_SNAPBACK}>

If the AutoitX function/method does not return any value, you can proceed as in your code.

If there is a return value, better capture the return value in a variable and check it for error code. Alternatively, you can use the .error() also to track the error.

Link to comment
Share on other sites

I'm not 100% sure what you mean there. When you say "the return value" you're talking about the value that tells you if the function was succesful right? So then I should add an if statement to handle the possability of a failiure by i.e. running the function again?

What are the ()'s for?

When I try to run my code it tells me that "AIX" is an "invalid outside procedure". I copied the dll into my system32 dir and registered the dll with regsvr32.exe. Is there another step that I missed?

Link to comment
Share on other sites

I'm not 100% sure what you mean there.  When you say "the return value" you're talking about the value that tells you if the function was succesful right?  So then I should add an if statement to handle the possability of a failiure by i.e. running the function again?

What are the ()'s for?

When I try to run my code it tells me that "AIX" is an "invalid outside procedure".  I copied the dll into my system32 dir and registered the dll with regsvr32.exe.  Is there another step that I missed?

<{POST_SNAPBACK}>

If the AutoIT functions returns any value ( telling u whether the function was successful or not ), you need to handle the return value.

Regarding the error, pl check for the below:

1) make sure, you have added the autoitX3.dll (Reference) by choosing Project -> Reference -> Select the AutoitX3.10 LIbrary in VB.

2) Make sure, you have the line "Dim AIX As New AUTOITX3Lib.AutoItX3" in General Declarations of the code section.

Link to comment
Share on other sites

Ok I got the error fixed. I hadn't added it in the refference menu. :">

Regarding the error handling, Im still not clear on that issue. Mainly Im not sure what the differences are between the two options you mentioned, and I am also not sure how they work, how to implement them, etc... Is there a info document that discusses them in detail? Also what is your demo project about?

Link to comment
Share on other sites

whenever u call a autoitX function or method, it may return value via 2 options depending on the function/method.

1) if the function/method has a return value ( refer to the function/method in AutoitX help file), you can use this return value to track the error or further processing.

2) Apart from returning a value, the function/method may also set the @error value in autoitX. Using the @error value also, you can track the error.

Example:

Dim AIX As New AUTOITX3Lib.AutoItX3

dim intError as integer
dim intResult as integer

intResult = aix.winexists("win title","win text")
interror = aix.error

Whether to choose the return value or the @error value to track result/error depends on the function/method that you call.

If the function does not return any return value but the @error is set, then you can use the @error value to track error.

Link to comment
Share on other sites

Ok so does @error work for all the AutoItX commands or just some?

What I'm not sure about is why you are setting the value of intResult to "aix.winexists("win title","win text")". Does the intResult variable actually get set to 0 or 1 depending on if the "winexists" function is succesful?

So tell me if I'm on the right track here.

If intResult = 0 Then    (or intError..?)
    ---- Do error handling code here...
End If
Link to comment
Share on other sites

Ok so does @error work for all the AutoItX commands or just some?

What I'm not sure about is why you are setting the value of intResult to "aix.winexists("win title","win text")".  Does the intResult variable actually get set to 0 or 1 depending on if the "winexists" function is succesful?

So tell me if I'm on the right track here.

If intResult = 0 Then     (or intError..?)
    ---- Do error handling code here...
End If

<{POST_SNAPBACK}>

Not all AutoitX functions use @error. U can use either the return value or the @error depending on whether the function/method uses return value or @error.

AutoitX DLL Help file has info on whether a function/method return value or sets @error value.

For example, when you try to open a file, the @error will be very useful whereas the @error is not used during winexists().

Link to comment
Share on other sites

Ok.

So I'm still confused about something.

Why did you set the value of intResult to "aix.winexists("win title","win text")". Does the intResult variable actually get set to 0 or 1 depending on if the "winexists" function is succesful?

Link to comment
Share on other sites

Ok.

So I'm still confused about something.

Why did you set the value of intResult to "aix.winexists("win title","win text")".  Does the intResult variable actually get set to 0 or 1 depending on if the "winexists" function is succesful?

<{POST_SNAPBACK}>

Yes. You are right.

the intResult variable get actually 0 or 1 depending on if the winexists function is successful.

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