Sign in to follow this  
Followers 0
RogerRabbitsClone

GUIctrlsetonevent with variable function names

5 posts in this topic

hello autoiters,

i want to create functions from within a for loop and give them names from items in an array.

for $s = 1 to $swfgames [0]
    $name = StringTrimRight($swfgames[$s], 4)
    $v = execute($name)
    Func $v()
        shellexecute (@scriptdir & "\gamez\flashplayer_10_sa.exe", @scriptdir & "\files\swf\" & $name)
    EndFunc
next

when i run the above code it tell me

" "For" statement has no matching "Next" statement.:"

wtf.

 

the entire program im writing will pull names of a bunch of .swf (flash) games from a local folder, then create a dynamic GUI to launch them from buttons. i got that part done (i think) but i cant connect GUICtrlsetonevent to each game. full program below and the game files are attached if you'd like to try it out.  look at line 55 for the correct directory to put them in.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>

Global $swfgames = _FileListToArray(@scriptDir & "\files\swf\", "*", 1), $howmanygames = $swfgames[0]

func main()
    Opt("GUICoordMode", 2)
    Opt("GUIOneventmode", 1)
    Opt("GUIResizeMode", 1)
    
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
    
    $size = $howmanygames * 30 ;this is the heoght of the GUI window
    GUICreate ("I Like Flash Gamez", 300, $size)
    $firstrow = $howmanygames / 2 ;this determines the size of the left column
    $secondrow = $firstrow + 1 ;this is the size of the right column
    
;~ these are the functions to create the buttons for the games
;~ this is the left column
    For $I = 1 To $firstrow
        local $x, $height1 = 30
        $height1 = $height1 + 30
        $name = StringTrimRight($swfgames[$I], 4)
        GUICtrlCreateButton ($name, 10, $height1)
        GUIctrlsetonevent(-1, $name)        
    Next
    
;~ this is the right column
    For $I = $secondrow To $swfgames[0] 
        local $y, $height2 = 30
        $height2 = $height2 + 30
        $name = StringTrimRight($swfgames[$I], 4)
        GUICtrlCreateButton ($name, 160, $height2)
        GUICtrlSetOnEvent(-1, $name)
    Next
    
    GUISetState(@sw_show)
    
    While 1
        sleep (10)
    WEnd
    
EndFunc

for $s = 1 to $swfgames [0]
    $name = StringTrimRight($swfgames[$s], 4)
    $v = execute($name)
    Func $v()
        shellexecute (@scriptdir & "\gamez\flashplayer_10_sa.exe", @scriptdir & "\files\swf\" & $name)
    EndFunc
next

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE

    EndSelect
EndFunc

func errorcheck()
    local $filesdir = (@scriptdir & "\files"), $swfdir = @scriptdir & "\files\swf"
    Select
        case not FileExists($filesdir)
            MsgBox (48, "Whoops!", "Looks like the data directory:" & @CRLF  & $filesdir & @CRLF &  "doesnt exist! Read the 'readme.txt' file!")
        case not FileExists($swfdir)
            MsgBox (48, "Whoops!", "Looks like the game directory:" & @CRLF  & $swfsdir & @CRLF & "doesnt exist! Make sure you have this folder and it is filled with .swf games!")
        case not FileExists($swfdir & "\*")
            MsgBox (48, "Whoops!", "Looks like the game directory:" & @CRLF  & $swfsdir & @CRLF & "is empty! Make sure your .swf files are located in that folder.")
        case not FileExists ($files & "\flashplayer_10_sa.exe")
            MsgBox (48, "Whoops!", "Looks like you're missing the flash player!:" & @CRLF  & $filesdir & @CRLF & "Make sure the program 'flashplayer_10_sa.exe' is in the above directory or your games won't play.")
        EndSelect
    EndFunc

errorcheck()
main()

<--a good way to start you day

Share this post


Link to post
Share on other sites



You have a function inside your For loop, you can not do that.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

oh. do you know of a way i can create function names from array items?


<--a good way to start you day

Share this post


Link to post
Share on other sites

RogerRabbitsClone,


 then create a dynamic GUI to launch them from buttons

Please read the Forum rules (the link is also at bottom right of each page) - particularly the bit about not discussing game launching - before you post again.  Thread locked. :naughty:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0