Sign in to follow this  
Followers 0
DustinBowers

More Help for Noob

6 posts in this topic

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!

Share this post


Link to post
Share on other sites



Use "For" instead:

For $count = 1 to $Num
 If $Label1[$count] ... Then ...
Next


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Your labels are overlapping one another:

"GUICtrlCreateLabel("X", $i * 10, 10, 12, 12)"

whim

Edited by whim

Share this post


Link to post
Share on other sites

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.

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  
Followers 0