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

    • lattey
      By lattey
      hi,
      i have checkboxes and each checkbox that checked, i put in array. 
      now, im stuck on how to loop the checked array and store in in one variable. what i can do now, is only write the result into a text file. 
      below is the code:
      #include <GUIConstantsEx.au3> ;~ #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <Array.au3> Global $Count = 3 Global $CheckBoxP[$Count] Global $step[$Count] global $array1[1] Global $ExitResult $hGUI = GUICreate("Summary Steps", 500, 400) GUISetFont(12, 400, "Tahoma") GUICtrlCreateLabel( "Please Select the Summary Steps for Script Check", 70, 20) GUISetFont(10, 400, "Tahoma") Global $array_Pstep[3] = ["fix2","fix1","fix3"] global $step[3] = ["2","3","4"] $Spacing = 50 For $i = 0 To UBound($array_Pstep) - 1 $CheckBoxP[$i] = GUICtrlCreateCheckbox($array_Pstep[$i], 80, $Spacing + (20 * $i), 65, 17) Next $submit = GUICtrlCreateButton("Submit",180, 280, 80, 30) $exit = GUICtrlCreateButton("Exit",180, 320, 80, 30) GUISetState() While 1 $Msg = GUIGetMsg() Select case $Msg=$submit For $i = 0 To $Count - 1 If GUICtrlRead($CheckBoxP[$i]) = $GUI_CHECKED Then _ArrayAdd($array1, $step[$i]) EndIf Next Global $logfilerray = @WorkingDir & "\checkedlist.txt" FileDelete ($logfilerray) Global $readlogfile = FileOpen($logfilerray,1) for $a = 1 to UBound($array1) - 1 ;~ $var=$array1[$a] FileWriteLine($readlogfile,$array1[$a]) Next FileClose($readlogfile) Exit case $Msg=$exit $ExitResult = MsgBox(1,"Summary Step", "Continue to Exit ?") if $ExitResult = 1 Then ;ok Exit EndIf Exit EndSelect WEnd  
    • omicron
      By omicron
      How do you perform a nested loop function with a multidimensional array from 2 lists.
      for i in list1
      (open file) extract variable
          while open for i in list 2
          (open file2) extract variable
       
      var1 + var2 = (search term)

      The list sizes will more than likely consist of different lengths.
       
      What is the best approach to accomplishing this method?
             
    • omicron
      By omicron
      Hello!

      I am working on a function that I am just getting lost on. The goal is a multiple nested loop.

      Here are the steps:
      Contents of file1.txt::
      [topic] var1=Name var2=OtherName var3=SomeotheName Contents of file2.txt::
      [subTopic] top=sub1 top2=sub2 top3=sub3 The Shell I am working from::
      #include <file.au3> $file = "c:\yourfile.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) msgbox(0,'','the line ' & $i & ' is ' & $line) Next FileClose($file) Understanding however that the "msgbox" needs to then become a variable. in example the following::
      $file = "c:\yourfile.txt" FileOpen($file, 0) While true( prog.exe is running && "WinName" is open) do For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) ;Open File to log "current location of file 1" FileWriteLine ("filename", $i & ' is ' & $line) var = $line Next $file2 = "c:\yourfile.txt" FileOpen($file, 0) For $i = 1 to _FileCountLines($file) $line = FileReadLine($file, $i) ; OpenFile to log "Current location of file 2" FileWriteLine ("filename", $i & ' is ' & $line) Next FileClose($file2) FileClose($file) The goal in written form is the following ::

      While in "OpenWindow"
          read from file 1 starting at line 1 until end of file.
         file 1 is a list of names to be searched.
         With $line selected, add this element to the element in file 2.
       
      The search of a variables in list 1 and list 2 differ on the amount of posts that day. (This is not a web based platform, it is a game) I need to search 2 names and take a screenshot of the out put. The sizes of the names list depend on the activity of names at the time of search.
      This loop continues until all the names from both lists have been searched. Mostly in the format of::
      File1= item
      File2= Vendor
       
      Item + Vendor  ( Capture screen, scroll) -- Not sure how to detect if I need to scroll)
       
      Thank you for your help and support!
    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
×