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

    • 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.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) 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] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
    • Dzenan03
      By Dzenan03
      I want to make a while loop, that creates variables based on a array. For thist I created the array $iDsO with the number and the name of folders in an other folder. Every folder has a different name an I want to create variables(arrays) for each folder that show me all the files in that folder. For example: I have the Folder \Folder1. In it there are the Folders \1, \2, \3. In 1, 2 and 3 there are some files(.png). The array for Folder1 is $iDsO and now I want to crate the arrays $iDsO1, $iDsO2 and $iDsO3 with the files in them can I make something like this:
      While $iDs > 0 ;$iDs is the number of files in Folder1>> $iDsO[0] $iDs#here should come the Foldername for example '1'# = _FileListtoArray(@ProgramFilesDir&"\Folder1\"&$iDsO[$iDs]) $iDs = $iDs - 1 Wend So that in the End I have three variabels ($iDs1, $iDs2 and $iDs3)
       
      Is this posible or if not what could I do instead ( I don´t know the number of folders in Folder1 in the begining).
×