Jump to content
Sign in to follow this  
Spenhouet

Read out all functions and a following variable into an array.

Recommended Posts

Spenhouet

Hi Forum.

EDIT because of new needs...:

I want to read out the name of all functions and one variable in it into an array.

for example:

AutoIT:

func example1()
$description = "The first example"
endfunc
func example2()
$description = "The second example"
endfunc

$array[2][2]

$array[0][0] = "example1()"

$array[0][1] = "The first example"

$array[1][0] = "example2()"

$array[1][1] = "The second example"

1. There's a script with functions.

2. There's a script the GUI use to know what to do..

3. There's a GUI script.

.... and there are alot other scripts...

Someone writes a new function in the 1. script. (nothing more only in script 1.)

The script 3. is there to show all functions of script 1. to choose and let a choice run.

To show the existing functions it starts script 2. which returns all functions (and a describing variable) in an array to script 3. which shows them.

The function must only be written and is automatically announced.

clear? can someone help me?

thx

Spenhouet

Edited by Spenhouet

Share this post


Link to post
Share on other sites
hannes08

Hi Spenhouet,

can you show us what you've got so far?

I would loop through your code line for line, extract the function name and from the following lines the first variable.

  • Like 1

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
jdelaney

Read in the file, and run this:

$atest = StringRegExp ( $sString,"(?i)(?m:^|n)s*Funcs+(w+)s*(|.*$desctiption.*",3 )

*Note, used the function regular expression from George Gedye's PCRE Toolkit

Then you can loop through, where the loop steps 2...that way, $i = Function name, and $i+1 of the array is = description


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Spenhouet

can you show us what you've got so far?

I would loop through your code line for line, extract the function name and from the following lines the first variable.

Sounds good. But i found nothing to loop through the code...and nothing to get the following variable.

Any idea?

Read in the file, and run this:

$atest = StringRegExp ( $sString,"(?i)(?m:^|n)s*Funcs+(w+)s*(|.*$desctiption.*",3 )

*Note, used the function regular expression from George Gedye's PCRE Toolkit

Then you can loop through, where the loop steps 2...that way, $i = Function name, and $i+1 of the array is = description

I musst admit that i don't understande anything... what does all this ?i)?m:1|n.... thing mean? and where do i get $sString from...?

Share this post


Link to post
Share on other sites
hannes08

Spenhouet,

there are several ways to loop through a file line for line.

You can either use FilereadLine or _FileReadToArray ... Just look up the functions in the help file.

Use StringInStr() to find strings. Or use what jdelaney wrote: Regular expressions.


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
Spenhouet

Spenhouet,

there are several ways to loop through a file line for line.

You can either use FilereadLine or _FileReadToArray ... Just look up the functions in the help file.

Use StringInStr() to find strings. Or use what jdelaney wrote: Regular expressions.

The Problem is that i don't want to get it out of a other file. My Code which saves the function name and the variable should be in the same Script as the functions...

And everytime this script runs, it saves the tests to a xml file.

So i need a command that search in the own code...

you say i shoud use the help.. but i did and found nothing.

Share this post


Link to post
Share on other sites
hannes08

If you are using ScITE4AutoIt ( Link ) you can open the helpfile by pressing F1.

use the search or index function of the helpfile.

So just to understand you problem correctly: you want to write some sort of a logfile, right?

As far as I know (and that's not much ;) there is no way to tell what functions and variables are in the script.

If you want to debug your script you need to add some code to every function.


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
Spenhouet

If you are using ScITE4AutoIt ( Link ) you can open the helpfile by pressing F1.

use the search or index function of the helpfile.

So just to understand you problem correctly: you want to write some sort of a logfile, right?

As far as I know (and that's not much ;) there is no way to tell what functions and variables are in the script.

If you want to debug your script you need to add some code to every function.

haha year i know... xD im newbie in AutoIT but not a noob :)

And like i said... i didn't found something in the help :) -> year i know clearly how it works.. ^^

And no you don't understand it correctly.

My goal is to announce a knew writen function to another AutoIT script.

A log file is also comming but not jet.

But i have no presentable code...because i have no idea to start this action jet..

Share this post


Link to post
Share on other sites
hannes08

My goal is to announce a knew writen function to another AutoIT script.

I stil don't get what you're trying to do.... ;)


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
Spenhouet

I stil don't get what you're trying to do.... ;)

Ok, i try to explain.

I want to read out the name of all functions and one variable in it into an array.

for example:

AutoIT:

func example1()
$description = "The first example"
endfunc
func example2()
$description = "The second example"
endfunc

$array[2][2]

$array[0][0] = "example1()"

$array[0][1] = "The first example"

$array[1][0] = "example2()"

$array[1][1] = "The second example"

1. There's a script with functions.

2. There's a script the GUI use to know what to do..

3. There's a GUI script.

.... and there are alot other scripts...

Someone writes a new function in the 1. script. (nothing more only in script 1.)

The script 3. is there to show all functions of script 1. to choose and let a choice run.

To show the existing functions it starts script 2. which returns all functions (and a describing variable) in an array to script 3. which shows them.

The function must only be written and is automatically announced.

clear? can someone help me?

thx

Spenhouet

First post is edit.

Edited by Spenhouet

Share this post


Link to post
Share on other sites
jdelaney

Perform a FileRead ( yes, of your script's file...or even make a copy of the script to a seperate file durring run time, and read that in) into the variable = $sString

$atest = StringRegExp ( $sString,"(?i)(?m:^|n)s*Funcs+(w+)s*(|.*$desctiption.*",3 )

Then loop through the array that is returned like I mentioned above.

Edited by jdelaney
  • Like 1

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
hannes08

I assume that the "other scripts" are uncompiled, right?

I also assume that you have a list of filenames of the other script.

Try a code like this:

_FileReadToArray("path", $aContents)
For $i = 1 To $a_contents[0] - 1
    $iPos1 = StringInStr($aContents[$i], "Func ")
    If  $iPos1 > 0 Then
        $iPos2 = StringInStr($aContents[$i], "(")
        $sFunc = StringMid($a_contents[$i], $iPos1, $iPos2 - $iPos2)
        $iPos3 = StringInStr($aContents[$i + 1], "$description=")
        If $iPos3 > 0 Then
            $sDescription = StringMid($aContents[$i+1], $iPos3 + 13)
        Else
            $sDescription = 0
        EndIf
        ;Add Lines to your array
    Next
Next

I know this could be done way easier with PCRE but I'm not good at it. ;)


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
Spenhouet

Perform a FileRead ( yes, of your script's file...or even make a copy of the script to a seperate file durring run time, and read that in) into the variable = $sString

$atest = StringRegExp ( $sString,"(?i)(?m:^|n)s*Funcs+(w+)s*(|.*$desctiption.*",3 )

Then loop through the array that is returned like I mentioned above.

Now i understood what you are talking about^^ -.-

I have never seen a regular expression befor.....

I understand what it do but can't get it done by my own... -.-

The thing with Func works realy fine, but the description is not like i want it to be.

$description = "blablabla"

I only need the blablabla. It would be the best if it's also in a new column of the array.

You would realy help me if you can write that for me.

Edited by Spenhouet

Share this post


Link to post
Share on other sites
jdelaney

durring the loop, do some stringinstring, to get a count after the '=', then you can do a stringright of the (stringlen - stringinstring of the = )

Let me know if that doesn't make sense ;)

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Robjong

#include <Array.au3>
$a = _GetFunctionsAndDescriptionVarFromAutoItScriptSourceAndPutThemInA2DArrayPerformMatchingNowPleaseThankYouOhAndJustSoYouKnowThisFunctionReturnsFalseIfItFinds0MatchesAndExpectsTheFirstParameterToBeAutoItScript(FileRead(@ScriptFullPath))
_ArrayDisplay($a)
Func _GetFunctionsAndDescriptionVarFromAutoItScriptSourceAndPutThemInA2DArrayPerformMatchingNowPleaseThankYouOhAndJustSoYouKnowThisFunctionReturnsFalseIfItFinds0MatchesAndExpectsTheFirstParameterToBeAutoItScript($au3source)
    Local Const $description = "It's all in the name"
    Local $aArray = StringRegExp($au3source, "(?im)funch+(w+)h*(.*$s*(?:(?:dim|global|local)?(?:h+const)?)h*$descriptionh*=h*""([^""]+)""", 4)
    If @error Then Return SetError(1, 0, False)
    Local $aSubArray, $iUBound = UBound($aArray), $aReturn[$iUBound][2] = [[$iUBound]]
    For $i = 0 To $iUBound - 1
        $aSubArray = $aArray[$i]
        $aReturn[$i][0] = $aSubArray[1]
        $aReturn[$i][1] = $aSubArray[2]
    Next
    Return $aReturn
EndFunc   ;==>_GetFunctionsAndDescriptionVarFromAutoItScriptSourceAndPutThemInA2DArrayPerformMatchingNowPleaseThankYouOhAndJustSoYouKnowThisFunctionReturnsFalseIfItFinds0MatchesAndExpectsTheFirstParameterToBeAutoItScript

Edited by Robjong
  • Like 1

Share this post


Link to post
Share on other sites
jdelaney

hahaha, that function name is huge; epic


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Spenhouet

@Ronjong: WOW a little thank you to you.

Enjoy the show: ;):) :) ;):D:cheer: :cheer: :cheer: :cheer:

You are awesome!

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  

  • Similar Content

    • rm4453
      By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
    • TrashBoat
      By TrashBoat
      So Im trying to make a simple 2d game and make some sort of collision detection so why not to make a 2 dimensional array but i have no clue how  to write it in multiple lines
      Global $map[5,5] = [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0 _ [0,0,0,0,0] something like this but it doesn't work
    • Zein
      By Zein
      #include "..\Include\Array.au3" #include "..\Include\File.au3" #include "..\Include\AutoItConstants.au3" Local $aRetArray Local $sFilePath = "n.csv" _FileReadToArray($sFilePath, $aRetArray, ",") ; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",") _ArrayDisplay($aRetArray, "Original", Default, 8) The above code shows two versions of _FileReadToArray and both don't work as expected.
      The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

      I looked again at the documentation:
       
      #include <File.au3> _FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )
      And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
      I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

       
    • ternal
      By ternal
      Hi,
      Recently I have had the need to do a sort and then do a second sort while the item of the first sort stays the same ( double sorting , first on column x then while column x is the same sort column y).
      I did not put much efffort into error checking but so far I did not need it.
      For my applications so far it works perfectly however if someone is willing I want to test this extensivly.
      If anyone has big lists of random stuff to sort could you try this out please?
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArraySort_Double ; Description ...: ; Syntax ........: _ArraySort_Double (Byref $array[, $first_index = Default[, $second_index = Default[, $ascending = Default]]]) ; Parameters ....: $array - 2d array to sort. ; $first_index - [optional] first column to sort. Default is 0. ; $second_index - [optional] second column to sort. Default is 1. ; $ascending - [optional] ascending/descending. Default is 1. ; Return values .: 1 if no errors occured , -1 if errors occured ; Author ........: Ternal ; Remarks .......: Needs excessive testing. ; Related .......: _arraysort() ; =============================================================================================================================== Func _ArraySort_Double (byref $array, $first_index = Default, $second_index = Default, $ascending = Default) Local $temp_value Local $counter = 1 If UBound($array, $UBOUND_DIMENSIONS) <> 2 Then MsgBox(0, "error", "error") return -1 EndIf If $first_index = Default Then $first_index = 0 If $second_index = Default Then $second_index = 1 If $ascending = Default Then $ascending = 1 _ArraySort($array, $ascending, 0, 0, $first_index); you can alter settings of primary sort here If @error Then MsgBox(0, "error", @error) return -1 EndIf $temp_value = $array[0][$first_index] For $x = 1 to UBound($array, 1) - 1 If Mod( $x, 10000) = 0 Then ConsoleWrite("at " & $x & " of a total : " & UBound($array, 1) & @CRLF) If $array[$x][$first_index] = $temp_value Then $counter+= 1 If $x = UBound($array, 1) - 1 Then; do last line here(if last line is not a new item) _ArraySort($array, $ascending, $x - $counter, $x, $second_index);you can alter settings of secondary sort here(don't forget to place line 34 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf EndIf Else If $counter > 0 Then ;at least 2 of the same _ArraySort($array, $ascending, $x - $counter, $x - 1, $second_index);you can alter settings of secondary sort here(don't forget to place line 29 the exact same) If @error Then MsgBox(0, "error", @error) return -1 EndIf $counter = 1 EndIf EndIf $temp_value = $array[$x][$first_index] Next Return 1 EndFunc Kind regards, Ternal
    • TrashBoat
      By TrashBoat
      So I've made this script that detects how long i have held down my left mouse button for and stores the information in an array and then sorts its using _ArraySort but the output is half sorted half broken.
      Here's my script:
      HotKeySet("{F1}","_exit") #include <Misc.au3> #include <Timers.au3> #include <Array.au3> Local $dll = DllOpen("user32.dll") $on = False Global $array[0] While(1) If _IsPressed(01,$dll) Then $timer = _Timer_Init() While _IsPressed(01,$dll) Sleep(1) WEnd $time = _Timer_Diff($timer) _ArrayAdd($array,"Time: " & Floor($time) & " ms") ;~ ConsoleWrite("Time: " & Floor($time) & " ms" & @CRLF) EndIf Sleep(50) WEnd Func _exit() _ArraySort($array) _ArrayDisplay($array) Exit EndFunc And the output:

      See how its not sorted?  What is the problem here?
×