Jump to content

Reading a textfile to call Functions


ndw
 Share

Recommended Posts

My apologies if the terminology in the title is wrong, if you can better word it, i'll edit it so others can search for it easier.

What i would like to do is have a script full of functions that do various things, i.e. click a certain position, drag a certain distance. Then i would like to have a textfile that listed these functions so when i read the textfile in, it executes them in order. So a textfile could read

OpenExplorer

Doubleclick(x,y)

RightClickCopy

And the program would read in "OpenExplorer" and run OpenExplorer(). Then read in Doubleclick(x,y) and run Doubleclick(x,y).

I know thats clear as mud but hopefully you understand what i mean. Is this possible? Calling a function from a read in string/variable? My end vision for this is to create test scripts as textfiles that can be easily editted and created.

Link to comment
Share on other sites

  • Moderators

ndw,

My end vision for this is to create test scripts as textfiles that can be easily editted and created

And just how does this vision differ from an AutoIt script with the functions in a separate #include file? :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

ndw,

And just how does this vision differ from an AutoIt script with the functions in a separate #include file? ;)

M23

Sorry, badly wrote that. I meant to say i'll have an Auto IT script with loads of Functions in it, with text files that can be read in which cherry picks which to run. I was thinking about sticking all the functions in their own files but... i have no idea about the include stuff :graduated: It might be ebtter in the long run to to that but, i'll leave that for another day.

Link to comment
Share on other sites

The word actually is Call(), see helpfile :graduated:

I have this working now for my functions that don't require arguements, but for something that does require arguements, i guess i'm gonna have to do something clever? In the file, let's say i have a some text that says "Reposition($x,$y,20,20)" where $x and $y are integers already definied earlier in the script. Do i need some kind of method that will break down the string in to characters, and stop at "(" ")" and "," and start cutting up the string to an array? Currently using FileReadLine.

Link to comment
Share on other sites

I've managed to work myself a mountain out of a mole hill on this one. I've written out some code to show what i'm trying to do.

The issue i have is determining how many arguements there are. I have some Functions that don't require any parameters, and others that have a few. I don't know of a way to make it able to handle any number of parameters.

Local $textfile, $i, $text, $array, $num1, $num2
 
    $textfile = FileOpen("textfile.txt")
    $num1 = Random(0,10)
    $num2 = Random(0,10)
 
    For $i = 1 to _FileCountLines("textfile.txt")
 
        $text = FileReadLine($textfile,$i)
        ; Format of text in file "Addition;$num1;$num2;7", but some functions have no arguements
        $array = StringSplit($text, ";")
 
        ; This would call a function with no arguements
     ; Call($array[0])
 
        ; But how would you call a function when you don't know how many arguements there are?
        Call ($array[0], $array[1]) ; $array[2] etc..
    Next
 
    Func Addition ($a, $b, $c)
 
        Msgbox (0,"Number", $a+$b+$c)
    EndFunc

I hope i've made this clear enough. I was stuck on the _FileCountLines for a while till i realised it was cause i was using the file handle when it can only deal with the path, which is a shame.

Link to comment
Share on other sites

I was stuck on the _FileCountLines for a while till i realised it was cause i was using the file handle when it can only deal with the path, which is a shame.

You could always copy the function to your script and edit it to use a handle.
Link to comment
Share on other sites

You could always copy the function to your script and edit it to use a handle.

Oh ok, i thought there might be some issue with editting somebody else's work or something silly but i'll look in to the after, it's working just not exacting as i want it. More concerned about the Call function and how to tackle that :graduated:
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...