DustinBowers Posted January 29, 2010 Share Posted January 29, 2010 Hi. Thanks for taking the time to look at my post. I've written a function which places a variable number of labels on a form $Label1[$Num] the user defines the number and a while / wend loop places them from 1 to the user defined var $Num. After it places these labels i will need a number of case statements to go with the number of user defined labels ex: Case $Label1[1] Case $Label1[2] Case$Label1[3] etc.. I have tried a for loop and a while/wend loop, i cant seem to make the case statements = the $Num of user defined labels which were generated, all i need is the case statements so that when the user click any of the labels they are deleted. I'm sure there is a way to loop through this array i'm just not sure how. Any help would be great. Thanks! Link to comment Share on other sites More sharing options...
water Posted January 29, 2010 Share Posted January 29, 2010 Use "For" instead:For $count = 1 to $Num If $Label1[$count] ... Then ... Next My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
DustinBowers Posted January 29, 2010 Author Share Posted January 29, 2010 I just tried your idea for the For loop, for testing purposes i set the user defined variable to a static number of 5 labels so i could more quickly test the looping for user input. but now that i placed the For loop in it automatically selects the last label placed without offer the user the ability to select for themselves by clicking the label Below is the code im using: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $i = 0 Local $Label1[400] Local $Mouse[2] Local $CountLabels = 0 $Form1 = GUICreate("Form1", 633, 447, 193, 125) GUISetState(@SW_SHOW) While $i <= 5 If $i = 5 then exitloop sleep(250) $Label1[$i] = GUICtrlCreateLabel("X",$i * 10, 10, 12, 12) $i = $i + 1 Wend While 1 $nMsg = GUIGetMsg() For $CountLabels = 0 to $i Step 1 If $Label1[$CountLabels] = $nMsg then MsgBox(0,"", "You pushed the Button " & $CountLabels) endif Next Wend Link to comment Share on other sites More sharing options...
water Posted January 29, 2010 Share Posted January 29, 2010 (edited) Something like this: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Local $Label1[400] Local $MaxLabels = 5 Local $Mouse[2] Local $CountLabels = 0 $Form1 = GUICreate("Form1", 633, 447, 193, 125) GUISetState(@SW_SHOW) For $i = 0 To $MaxLabels Sleep(250) $Label1[$i] = GUICtrlCreateLabel("X", $i * 10, 10, 12, 12) Next While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case Else For $i = 0 To $MaxLabels If $Label1[$i] = $Msg Then MsgBox(0, "", "You pushed the Button " & $i) EndIf Next EndSelect WEnd Edited January 29, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
whim Posted January 29, 2010 Share Posted January 29, 2010 (edited) Your labels are overlapping one another: "GUICtrlCreateLabel("X", $i * 10, 10, 12, 12)" whim Edited January 29, 2010 by whim Link to comment Share on other sites More sharing options...
DustinBowers Posted January 29, 2010 Author Share Posted January 29, 2010 Thanks! I knew it was something as easy as that. LOL I just didnt know exactly how to do it. Much better than having 400 case statements. : ) Thanks a bunch. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now