Sign in to follow this  
Followers 0
gcue

build an array using a secondary script

15 posts in this topic

can i have a secondary script kick off from a primary script that builds an array AND still makes the array available for queries in the primary script? if so, how?

heres how the array is build (then later access the $avOUT array values):

; Read file in binary mode
    $hFile = FileOpen($sFile, 16)
    $binFileData = FileRead($hFile)
    FileClose($hFile)

    ; Change nulls
    $sFileData = BinaryToString($binFileData, 1)
    $sFileData = StringReplace($sFileData, Chr(0), "<null>")

    ; Split lines
    $avLines = StringSplit($sFileData, @CRLF, 1)

    Global $avOut[$avLines[0] + 1][2] = [[$avLines[0], ""]]; Start out with minimum two columns

    ; First loop - for each row
    For $n = 1 To $avLines[0]
        ; Split the line
        $avSplit = StringSplit($avLines[$n], $DELIM)

        ; Test if more columns are needed
        If $avSplit[0] > UBound($avOut, 2) Then ReDim $avOut[$avLines[0] + 1][$avSplit[0]]

        ; Second loop for each column
        For $x = 1 To $avSplit[0]
            $avOut[$n][$x - 1] = $avSplit[$x]
        Next
    Next

Share this post


Link to post
Share on other sites



I used sort-of a multithreaded hack in a CPU temp program I made that gathered the processor usage via a WMIService = ObjGet ordeal... Well, the object interactions were taking up to like 500ms or even 1.5 seconds, in the mean time I have a tooltip that was supposed to be following the mouse on a pretty 'live' basis... Can we say.. Fail? lol

I done something like this, in short...

$Temp = _ACPI_Temp()

$Usage = IniRead(@AppDataDir & "\CpuTemp\Settings.ini","CPUTemp","Percent","0")

The second program, which extracts from the exe, and executes hidden... Writes to that INI as fast as it can... That was 'my' fix for multithreading... lol

After rereading your post again, and again... I don't fully understand the question... There are scripts all over the forums that allows communication between one another? Or am I looking at it wrong... :P

Share this post


Link to post
Share on other sites

Maybe WM_COPYDATA? or Virtual allocation? or MemoryMappedFile?

Share this post


Link to post
Share on other sites

no i think u get the just of it..

i just dont want to interrupt the first script while the second one builds the array...

after it builds the array, can it exit?

Share this post


Link to post
Share on other sites

gcue,

Why not make the first script call the second, which builds the array and saves it as a file while the first carries on doing whatever it is you want it to do rather than create the array. Then read that file back into your first script once it has been created.

You may have to do a bit of coding to get the 2D $avSplit array into a file with a suitable format, but that would not be too difficult.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

can i have a secondary script kick off from a primary script that builds an array AND still makes the array available for queries in the primary script? if so, how?

heres how the array is build (then later access the $avOUT array values):

; Read file in binary mode
    $hFile = FileOpen($sFile, 16)
    $binFileData = FileRead($hFile)
    FileClose($hFile)

    ; Change nulls
    $sFileData = BinaryToString($binFileData, 1)
    $sFileData = StringReplace($sFileData, Chr(0), "<null>")

    ; Split lines
    $avLines = StringSplit($sFileData, @CRLF, 1)

    Global $avOut[$avLines[0] + 1][2] = [[$avLines[0], ""]]; Start out with minimum two columns

    ; First loop - for each row
    For $n = 1 To $avLines[0]
        ; Split the line
        $avSplit = StringSplit($avLines[$n], $DELIM)

        ; Test if more columns are needed
        If $avSplit[0] > UBound($avOut, 2) Then ReDim $avOut[$avLines[0] + 1][$avSplit[0]]

        ; Second loop for each column
        For $x = 1 To $avSplit[0]
            $avOut[$n][$x - 1] = $avSplit[$x]
        Next
    Next
Hi gcue, (No I haven't forgotten about your other problem :P )

It depends what information you need to pass between the 2 scripts. If you want ScriptA to get information like what is the value of array[a] then it could be fairly easy, but if you want scriptb to send the whole array to scripta then it could be quite difficult, or at least long-winded. You could just write the whole array to a file and scriptA can read it, or you can use messages.

It would be much easier if you could just have a function rather than another process.


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

martin!!!

i want scriptA to read an array that scriptB creates

but if i write the whole array to a file doesnt it take long to read it?

Share this post


Link to post
Share on other sites

Maybe WM_COPYDATA? or Virtual allocation? or MemoryMappedFile?

How you would use a MemorymappedFile to share an array between two AutoIt processes?


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

so is it pretty problematic to do it with scriptA and scriptB ??

Share this post


Link to post
Share on other sites

The read and write functions don't take but a fraction, of a fraction of a second... Or at least they don't on my PC... I'm not sure about FileRead & Write, but IniRead Write are fast as lightning, unless you have an Array the size of... err... Like HUGE... :P

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

ya its huge.. the txt file is 16mb (16,000 rows or something)

Edited by gcue

Share this post


Link to post
Share on other sites

ya its huge.. the txt file is 16mb (16,000 rows or something)

I tried reading 5.8Mb and it took less than 100mS with FileRead so it might not be a problem. Sorting it out into an array though might take more time because you can't just save and read arrays to files with AutoIt.


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

Maybe WM_COPYDATA? or Virtual allocation? or MemoryMappedFile?

authenticity, can you show me a simple example?

Share this post


Link to post
Share on other sites

App1.au3

#include <SendMessage.au3>
#include <WindowsConstants.au3>
HotKeySet('{ESC}', '_Close')

If Not IsDeclared('HWND_BROADCAST') Then _
Global Const $HWND_BROADCAST = 0xFFFF
Global Const $tagCOPYDATASTRUCT = _
    'dword dwData;' & _
    'dword cbData;' & _
    'ptr lpData;'


Global Const $hWnd = WinGetHandle(AutoItWinGetTitle())
Global $avTestArr[Random(10, 20, 1)][2]

AdlibEnable('_SetDataNotify', 10000)

While 1
    Sleep(20)
WEnd

Func _Close()
    Exit
EndFunc

Func _SetDataNotify()
    Local $tBuffer = DllStructCreate('char[4096]')
    Local $tCDS = DllStructCreate($tagCOPYDATASTRUCT), $pCDS = DllStructGetPtr($tCDS)
    Local $sString = ''
    
    For $i = 0 To UBound($avTestArr) -1
        $avTestArr[$i][0] = Random(200, 400)
        $avTestArr[$i][1] = Random(-400, -200)
        $sString &= $avTestArr[$i][0] & '@' & $avTestArr[$i][1] & '|'
    Next
    
    DllStructSetData($tBuffer, 1, StringTrimRight($sString, 1))
    DllStructSetData($tCDS, 'dwData', 0x50125439)
    DllStructSetData($tCDS, 'cbData', DllStructGetSize($tBuffer))
    DllStructSetData($tCDS, 'lpData', DllStructGetPtr($tBuffer))

    _SendMessage($HWND_BROADCAST, $WM_COPYDATA, $hWnd, $pCDS)
EndFunc

App2.au3

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet('{ESC}', '_Close')

If Not IsDeclared('HWND_BROADCAST') Then _
Global Const $HWND_BROADCAST = 0xFFFF
Global Const $tagCOPYDATASTRUCT = _
    'dword dwData;' & _
    'dword cbData;' & _
    'ptr lpData;'


Global $hGUI = GUICreate('')
Global $hWndFrom = 0, $avArray[1]

GUIRegisterMsg($WM_COPYDATA, 'WM_COPYDATA')

While 1
    Sleep(10)
WEnd

Func _Close()
    Exit
EndFunc

Func WM_COPYDATA($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tCDS = DllStructCreate($tagCOPYDATASTRUCT, $ilParam)
    Local $tBuffer
    Local $sString
    Local $avRows, $avCols
    
    If DllStructGetData($tCDS, 'dwData') = 0x50125439 Then
        $tBuffer = DllStructCreate('char[4096]', DllStructGetData($tCDS, 'lpData'))
        $sString = DllStructGetData($tBuffer, 1)
        $avRows = StringSplit($sString, '|')
        If Not @error Then
            $avCols = StringSplit($avRows[1], '@')
            If Not @error Then
                ReDim $avArray[$avRows[0]+1][$avCols[0]+1]
            
                For $i = 1 To $avRows[0]
                    $avCols = StringSplit($avRows[$i], '@')
                    If UBound($avArray, 2) < $avCols[0] Then ReDim $avArray[$avRows[0]+1][$avCols[0]+1]
                    
                    For $j = 1 To $avCols[0]
                        $avArray[$i-1][$j-1] = $avCols[$j]
                    Next
                Next
                
                $hWndFrom = $iwParam
                AdlibEnable('_AdlibHelper', 50)
            EndIf
        EndIf
    EndIf
    
    Return $GUI_RUNDEFMSG
EndFunc

Func _AdlibHelper()
    AdlibDisable()
    If IsArray($avArray) Then _ArrayDisplay($avArray, 'From: ' & $hWndFrom)
EndFunc

Hopefully some windows or new untitled documents won't jump. It's just to illustrate. Another approach would be to get a specific window handle in some way, i.e. application parameters or using a unique message using _WinAPI_RegisterWindowMessage() with a unique GUID or something. You're not actually sharing anything but it can be handled this way. MemoryMappedFile require more code but concept is probably ~same.

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