Jump to content

Recommended Posts

Posted

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!

Posted

Use "For" instead:

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Your labels are overlapping one another:

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

whim

Edited by whim

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
×
×
  • Create New...