Jeremy Campbell
asked on
Can I call a particular Autoit function in a running Autoit Script from Access VBA?
I am able to launch a script from VBA and pass parameters to that script but I would like to be able to just active a particular function on an already running script from VBA as well as pass parameters to it.
Is this possible or am I limited to launching a script from VBA?
Thanks for the help!
Is this possible or am I limited to launching a script from VBA?
Thanks for the help!
VBA isn't a scripting language and I don't know what autoit is. If you are asking if you can run a script from Access then the answer is you can but there is no way to jump into it in the middle. I think if you wanted to only execute part of a script, you would need to isolate that into its own script and execute just that which of course would require modifying the original script also.
@PatHartman - AutoIT is an automation tool with it's own structure (used mostly for automating things like GUIs by scanning the app for form/control names and performing interaction on it).
If you have some sample code it's going to explain a lot more, because I'm not 100% clear on what you are looking to accomplish.
If you have some sample code it's going to explain a lot more, because I'm not 100% clear on what you are looking to accomplish.
The question should focus more.on what you try to accomplish...Autoit is great for scripting and system macros but VBA is far more powerful and maybe it is easier to accomplish than you think
ASKER
VBA:
Shell ("\\sapp0\dbs\Applications \Permissio ns\Scripts \JobAdjust ment.exe " & "Qty " & Me.jaJobNum & " " & Me.jaAssemblySeq & " " & Me.joOprSeq & " " & RemQty) <--- Insert a Call QtyAdj() function from here in VBA.
AutoIT Script: (The VBA code only runs the Func within the AutoIT script that it calls)
Func ClaimSetup()
;Do stuff here
EndFunc
Func QtyAdj()
;Do some stuff here using parameters from VBA
EndFun
Shell ("\\sapp0\dbs\Applications
AutoIT Script: (The VBA code only runs the Func within the AutoIT script that it calls)
Func ClaimSetup()
;Do stuff here
EndFunc
Func QtyAdj()
;Do some stuff here using parameters from VBA
EndFun
ASKER
This is how I'm currently handling this on the AutoIT side. I pass different values for the first parameter that the script then picks up as a Select Case to determine which set of code it should be running. This works great really, but I have another script that is running constantly in the backround until I fire off a hotkey which tells it to run a specific function. I would like to include additional functions in that script that is already running that I can call from VBA and still be able to pass parameters to.
Here is what it looks like from the VBA side:
Global $EpiClass = "WindowsForms10.Window.8.app.0.a70cb4_r17_ad1"
$MousePos = MouseGetPos()
WinActivate("Job Cost Adjustment")
WinMove("Job Cost Adjustment","",1680,-794)
MouseClick("left",1846 , -727,2,0) ; Clear Adjustment Form
ToolTip("Enter JobNum",0,0)
Do
sleep(10)
Until PixelGetColor(2012,-669) = 0
Send ($CmdLine[2])
ToolTip("Enter ASM",0,0)
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 61]") ;ASM
Do
sleep(10)
Until PixelGetColor(2271,-517) = 3381759
Send ($CmdLine[3])
Send ("{HOME}")
ToolTip("Enter Opr",0,0)
Do
sleep(10)
Until PixelGetColor(2269,-518) = 0
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 60]") ;Opr
Do
sleep(10)
Until PixelGetColor(2503,-517) = 3381759
Send ($CmdLine[4])
Send ("{HOME}")
ToolTip("Enter Employee",0,0)
Do
sleep(10)
Until PixelGetColor(2501,-518) = 0
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 39]") ;Employee
Do
sleep(10)
Until PixelGetColor(2012,-358) = 0
Sleep(100)
Send("999")
Sleep(10)
ToolTip("",0,0)
select
case $CmdLine[1] = "Setup"
Local $Complete = 0
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 46]") ;Setup Radial
Do
sleep(10)
Until PixelGetColor(2451,-338) = 3381759
Send("{SPACE}")
Sleep(10)
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 24]") ;Complete:
Do
sleep(10)
Until PixelGetColor(2517,-290) = 3381759
Do
Sleep(10)
if PixelGetColor(2510,-281) <> 4939927 Then
Send("{SPACE}")
ToolTip(PixelGetColor(2510,-281),0,0)
Else
$Complete = 1
EndIf
Until $Complete = 1
$Complete = 0
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 25]") ;Complete:
Do
sleep(50)
Until PixelGetColor(2518,-314) = 3381759
Do
Sleep(50)
if PixelGetColor(2510,-305) <> 4939927 Then
Sleep(50)
Send("{SPACE}")
ToolTip(PixelGetColor(2510,-305),0,0)
Else
$Complete = 1
EndIf
Until $Complete = 1
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 21]") ;Complete:
ToolTip("",0,0)
Case $CmdLine[1] = "Qty"
Local $Complete = 0
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 44]") ;Production Radial
Send("{SPACE}")
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 34]", "Left", 2) ;Labor Qty:
Do
sleep(50)
Until PixelGetColor(2011,-332) = 3381759
Send($CmdLine[5])
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 24]") ;Complete:
Do
sleep(10)
Until PixelGetColor(2517,-290) = 3381759
Do
Sleep(10)
if PixelGetColor(2510,-281) <> 4939927 Then
Send("{SPACE}")
ToolTip(PixelGetColor(2510,-281),0,0)
Else
$Complete = 1
EndIf
Until $Complete = 1
$Complete = 0
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 25]") ;Complete:
Do
sleep(50)
Until PixelGetColor(2518,-314) = 3381759
Do
Sleep(50)
if PixelGetColor(2510,-305) <> 4939927 Then
Sleep(50)
Send("{SPACE}")
ToolTip(PixelGetColor(2510,-305),0,0)
Else
$Complete = 1
EndIf
Until $Complete = 1
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 21]") ;Complete:
Case $CmdLine[1] = "Misc"
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 44]") ;Production Radial
Send("{SPACE}")
ControlClick("Job Cost Adjustments","","[CLASS:" & $EpiClass & "; INSTANCE: 34]", "Left", 2) ;Labor Qty:
ToolTip("",0,0)
EndSelect
MouseMove($MousePos[0],$MousePos[1],0)
Here is what it looks like from the VBA side:
Private Sub cmdClaimSetup_Click()
Shell ("\\sapp0\dbs\Applications\Permissions\Scripts\JobAdjustment.exe " & "Setup " & Me.jaJobNum & " " & Me.jaAssemblySeq & " " & Me.joOprSeq & " " & "0")
End Sub
Private Sub cmdMiscAdj__Click()
Shell ("\\sapp0\dbs\Applications\Permissions\Scripts\JobAdjustment.exe " & "Misc " & Me.jaJobNum & " " & Me.jaAssemblySeq & " " & Me.joOprSeq & " " & "0")
End Sub
I think I understand what you're asking, is this correct:
You call an AutoIT script that runs a specified function but within that function you want to be able to conditionally run other functions with variables passed in?
You call an AutoIT script that runs a specified function but within that function you want to be able to conditionally run other functions with variables passed in?
So i guess you are trying to "autocomplete" a form on an applications....at first have you checked if the application you are trying to "control" exposes an API that you can connect and execute various operations..For example in the ERP on the company i worked there was a nice API that you could connect from virtually anywhere(VBA,VB6,.NET) so this should be the starting point...
If this is not possible then there are 2 options....
If this is not possible then there are 2 options....
- The application that you need to fill the data as any other application needs to store its data somewhere...normally to a database engine (MSSQL,Oracle,MySQL....)..
.so you profile what the application "writes" and you mimic it....
- If this is not desired then AutoIT as far i know is a simple text file which is compiled ....so you could have "templates" and do string replacements to achieve what you need (values to enter) and then compile it from Access and execute it
ASKER
Hey John, Thanks for replying to this. You are exactly right in your thoughts on trying to use an API to input the data. We have not gotten that far with the understanding of the software yet but it is on the very near horizon. The software is Epicor ERP and we would love to know how to use there business objects to input data. From what I understand that can be done through .net but I don't even know where to get started to accomplish that.
I believe in the next version that's out there they have a new service called REST where you it's much easier to do these things. If there is a way I could get some help trying to do this in our current version (they said it could be done but was just a little more complicated) that would be great.
We already tie directly into the backend of the ERP database but just for extracting information. We do not push data back there for obvious reasons and would like to go through there business objects.
I believe in the next version that's out there they have a new service called REST where you it's much easier to do these things. If there is a way I could get some help trying to do this in our current version (they said it could be done but was just a little more complicated) that would be great.
We already tie directly into the backend of the ERP database but just for extracting information. We do not push data back there for obvious reasons and would like to go through there business objects.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.