Jump to content

Create Functions in a Loop


Recommended Posts

Hi, is it possible to create functions in a loop? e.g.:

for $i = 0 To 10 Step +1
    Func $i()
        MsgBox(0, "Name", "I am function" & $i)
    EndFunc
Next

Thank you!

Sorry to be blunt... but no. What is your purpose? There is probably a better way to do it.
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

well then just do it the other way around, basicly what you are asking for.

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

for $i = 0 To 10 Step +1
    somefunc($i)
Next

Func somefunc($i)
    MsgBox(0, "Name", "I am function" & $i)
EndFunc

Hehe know what you mean btw. Search the forum, you can use some execute or something like that, then you can execute code not depending on a set environment variable.

Edited by jokke
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

I want to build a "dynamic" contextmenu. On execution my program reads data out of a database and should create a menuitem for every "piece of data" in the contextmenu, which is connected to a function (GUI event mode on).

I have created lots of GUIs with dynamic controls and I prefer GuiOnEventMode for all my GUIs.

The way you handle that it to have a single function that handles whole classes of control actions, like _ButtonHit() for all your buttons. Inside that function, you make use of @GUI_WINHANDLE, @GUI_CTRLID, etc. to detect which control to act on.

I think you'll find that much more logical and easier to code than "dynamic function declarations".

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

To get you started:

#include <File.au3>
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)  
HotKeySet("{ESC}","close")
Global $array
_FileReadToArray(@ScriptDir&"\test.txt",$array)

Global $ids[UBound($array)]
For $i=1 To UBound($array)-1
    $ids[$i]=TrayCreateItem($array[$i])

    TrayItemSetOnEvent(-1,"_Handler")
Next

Do
    Sleep(100)
Until False


Func _Handler()
    For $i=0 To Ubound($array)-1
        If $ids[$i]=@TRAY_ID Then
            MsgBox(0,"Clicked",TrayItemGetText($ids[$i]))
            ExitLoop
        EndIf
    Next
EndFunc

Func close()
    Exit
EndFunc

Creates a tray item for every line in a text file ;)

Broken link? PM me and I'll send you the file!

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...