Sign in to follow this  
Followers 0
marcianopro

Passing Variables from vbscript program to Autoit Program

8 posts in this topic

Hi

I am trying to write a script in Amibroker which uses vbscript and Jscript as hosts. However, though new to programming I found Autoit much more versatile.

What I am Trying to Achieve :

----------------------------------

Amibroker is the Technical Analysis tool which based on certain day trading rules provides the following Information.

- Trade Type : Buy or Sell

- Buy / Sell Price

- Value of a particular Technical Indicator (MACD)

These 3 information is captured by vbscript

vbscript to launch Autoit script which takes the Trade Type & Buy/Sell Price as two parameters. It opens the webpage of Trading site, uses Username & password to login in and navigates to Trading form. Based on the above three parameters it places the Order on the site and monitors the trade. In order to monitor the trade autoit script would require to be constanty updated with the MACD value. whenever the MACD value crosses Zero the trade has to be terminated.

Limitations :

--------------

-Unfortunately I couldnot find any way of Autoit directly interacting with Amibroker since it supports only vbscript & jscript hosts.

- I have written a script in vbscript, which is able to login the web site and able to place order. Based on the trading rules being met, the vbscript needs to pass on the 3 parameters to autoit. Would appreciate if someone can help me in giving possible ways to aschieve this.

- I tried using AutoitX3.Control in vbscript but faced a serious problem. with this setup the autoit UDFs just do not work at all and give errors.

Help Required :

-----------------

1. How to launch the autoit script from vbscript ?

2. While launching autoit script 3 parameters from vbscript to be passed on to autoit ?

3. Any change in any of the 3 variables to be constantly passed on to autoit script.

I would appreciate if anyone can help me in this regard. My apologies, I am new to Scripting be it vbscript or autoit, but am confident that with a broad direction would be able to achieve what i want.

Share this post


Link to post
Share on other sites



Hi

I am trying to write a script in Amibroker which uses vbscript and Jscript as hosts. However, though new to programming I found Autoit much more versatile.

What I am Trying to Achieve :

----------------------------------

Amibroker is the Technical Analysis tool which based on certain day trading rules provides the following Information.

- Trade Type : Buy or Sell

- Buy / Sell Price

- Value of a particular Technical Indicator (MACD)

These 3 information is captured by vbscript

vbscript to launch Autoit script which takes the Trade Type & Buy/Sell Price as two parameters. It opens the webpage of Trading site, uses Username & password to login in and navigates to Trading form. Based on the above three parameters it places the Order on the site and monitors the trade. In order to monitor the trade autoit script would require to be constanty updated with the MACD value. whenever the MACD value crosses Zero the trade has to be terminated.

Limitations :

--------------

-Unfortunately I couldnot find any way of Autoit directly interacting with Amibroker since it supports only vbscript & jscript hosts.

- I have written a script in vbscript, which is able to login the web site and able to place order. Based on the trading rules being met, the vbscript needs to pass on the 3 parameters to autoit. Would appreciate if someone can help me in giving possible ways to aschieve this.

- I tried using AutoitX3.Control in vbscript but faced a serious problem. with this setup the autoit UDFs just do not work at all and give errors.

Help Required :

-----------------

1. How to launch the autoit script from vbscript ?

2. While launching autoit script 3 parameters from vbscript to be passed on to autoit ?

3. Any change in any of the 3 variables to be constantly passed on to autoit script.

I would appreciate if anyone can help me in this regard. My apologies, I am new to Scripting be it vbscript or autoit, but am confident that with a broad direction would be able to achieve what i want.

If you compile the AutoIt (au3) script then you can run the script from VB like any other executable, and pass the 3 parameters. I don't know anything about VB but that must be a common sort of thing to do.

Once the AutoIt script is running you could still do the same thing provided the Au3 script was written to cope with it. If the au3 script sees that there is already another instance running then it can send a message to the previous instance giving the 3 values and then close. If that makes sense and you think that would be a reasonable way to do things then I can give some more help on how.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

If you compile the AutoIt (au3) script then you can run the script from VB like any other executable, and pass the 3 parameters. I don't know anything about VB but that must be a common sort of thing to do.

Once the AutoIt script is running you could still do the same thing provided the Au3 script was written to cope with it. If the au3 script sees that there is already another instance running then it can send a message to the previous instance giving the 3 values and then close. If that makes sense and you think that would be a reasonable way to do things then I can give some more help on how.

Share this post


Link to post
Share on other sites

If you compile the AutoIt (au3) script then you can run the script from VB like any other executable, and pass the 3 parameters. I don't know anything about VB but that must be a common sort of thing to do.

Once the AutoIt script is running you could still do the same thing provided the Au3 script was written to cope with it. If the au3 script sees that there is already another instance running then it can send a message to the previous instance giving the 3 values and then close. If that makes sense and you think that would be a reasonable way to do things then I can give some more help on how.

--------------

Thanks Martin.

Your suggested approach appears fine. Would appreciate if you can Provide more guidance and help.

I assume that whn the second instance of autoit program is created by vbscript and it discovers that one instance is already running then the new values of the three parametrs will be passed on to the already running autoit program instance. That appoach looks ok

Marcianopro

Share this post


Link to post
Share on other sites

Actually you could send data through TCP to yourself and the server to capture the packet.

Share this post


Link to post
Share on other sites

--------------

Thanks Martin.

Your suggested approach appears fine. Would appreciate if you can Provide more guidance and help.

I assume that whn the second instance of autoit program is created by vbscript and it discovers that one instance is already running then the new values of the three parametrs will be passed on to the already running autoit program instance. That appoach looks ok

Marcianopro

Here is more on what I suggested, but it might be worth asking xVivoCity how to use his suggestion because I don't think I know how to do that from what you've said so far.

In the Autoit script-

you first detect the parameters passed. These are $CmdLine[1] to $CmdLine[3] if 3 have been passed. The actual number passed is in $CmdLine[0].

Then check to see if there is another instance running. I use this function which is a modified version of _Singleton. (most people would use _Singleton)

$SecondInst =  MutexExists("SOmething@%Unlikely75421To9012exist___already") 


Func _MutexExists($sOccurenceName)
    Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError
    
    $sOccurenceName = StringReplace($sOccurenceName, "\", ""); to avoid error
    $handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $sOccurenceName)

    $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    Return $lastError[0] = $ERROR_ALREADY_EXISTS
    
EndFunc ;==>_MutexExists

If there is no instance already running then run as before, otherwise send the data to the first instance and exit.

There are various ways o send the data of course. The simplest is to have something like an edit, which could be hidden, and use ControlSend to send the data to the edit. The script has to keep looking to see if the data has changed.

Another way is using messages and ChrisL's UDF simplifies this.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@marcianopro

This is an example of how to run an Au3 EXE from Vbscript and passing parameter values to it.

As well as capturing the output from it.

Dim WshShell, oExec, Output, Result

Cmd = "C:\_\Apps\AutoIT3\COM\VBScript_COM\Test.exe _FV 3 100 10"

Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec(CMD)

'oExec.StdIn.Write _

'10000 & "|" & 3 & "|" & 24

'oExec.StdIn.WriteBlankLines(3)

oExec.StdIn.close

Output = oExec.StdOut.ReadAll()

Result = cdbl(Output)

WScript.Echo Output & vbCR & vbCR & " Returned from AU3" & vbCR

For more info see my signature : "Creating COM objects without a need of DLL's"

regards

ptrex

Share this post


Link to post
Share on other sites

@marcianopro

This is an example of how to run an Au3 EXE from Vbscript and passing parameter values to it.

As well as capturing the output from it.

For more info see my signature : "Creating COM objects without a need of DLL's"

regards

ptrex

-------------

Thanks martin and ptrex for the direction. Will try these and check if this works for me.

Marcianopro

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