Sign in to follow this  
Followers 0
Bert

buttons, text, and arrays

3 posts in this topic

I'm working on a docked toolbar I'm using for a app. I got the toolbar working fine, but I wanted to:

  • Give the user the option of only using the buttons they want to use(plan to use a option menu)
  • Sizing the toolbar to match what buttons are shown.
  • I want to have the buttons be sized by the amount of text in the button.
I know a array is the way to go, but how to do it is the problem. I did some searching, and couldn't quite find a good example. Any example code would be great.

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>
#include <Date.au3>

Dim $Header_1 = "Machine"
Dim $Header_2 = "Line"
Dim $Header_3 = "Office"
Dim $Name, $TotalTime, $Unit, $count
Dim $TimerActive_[50], $Label_[50], $TButton_[50], $SButton_[50], $Input_[50], $Label_[50]
Dim $Time_[50], $Timer_[50], $sTime_[50], $xk, $ck, $tk, $pk, $Left = 0, $Top = 20, $X, $Radx, $Rad_[11]

$Today_File = @MON & "-" & @MDAY & "-" & @YEAR & ".txt"
$Log = FileOpen($Today_File, 1)
FileWriteLine($Log, "Logfile started: " & _DateTimeFormat( _NowCalc(), 0) & @CRLF & @CRLF)
FileClose($Log)

$Toy_Logo = @TempDir & "\Toy2-logo.jpg"
FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box2-jpg.jpg", $Toy_Logo)
$Toy_Banner = @TempDir & "\Toy-banr.jpg"
FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box-jpg.jpg", $Toy_Banner)
$Logo_icon = @TempDir & "\Toy-Icon.ico"
FileInstall("C:\XPClean-web\Settings\XPClean-pics\Toy-box-Icon.ico", $Logo_icon)

Setup()

AdlibEnable("AllTimers", 500)

GUICreate("   Toy BOX  -  Multi-Station-Timer", (110 * $pk), 470)
GUISetIcon($Logo_icon)


;Top computer label
GUICtrlCreateLabel($Header_1 & "s", 0, 0, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 12, 700)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x876B53)

;Middle phones label
GUICtrlCreateLabel($Header_2 & "s", 0, 220, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 12, 700)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x876B53)

;Bottom PC label
GUICtrlCreateLabel($Header_3 & "s", 0, 340, (110 * $pk), 20, $SS_CENTER, $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 12, 700)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x876B53)

For $X = 1 To $pk
; row 1
    GUICtrlCreateLabel($Header_1 & " " & $X, $Left, $Top, 100, 20, $SS_CENTER)
    $Label_[$X] = GUICtrlCreateLabel("", $Left, $Top + 20, 100, 30, 0x1000)
    GUICtrlSetFont($Label_[$X], 16)
    GUICtrlSetData($Label_[$X], "00:00:00")
    $TButton_[$X] = GUICtrlCreateButton("Start", $Left, $Top + 50, 50, 20)
    $SButton_[$X] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 50, 50, 20)
    $Input_[$X] = GUICtrlCreateInput("", $Left, $Top + 70, 100, 20, 0x1000)
   ;MsgBox(0,$pk, $Radx & @CRLF & $count)
; row 2
    GUICtrlCreateLabel($Header_1 & " " & ($X + (($count +1)* .25)), $Left, $Top + 100, 100, 20, $SS_CENTER)
    $Label_[($X + (($count +1)* .25))] = GUICtrlCreateLabel("", $Left, $Top + 120, 100, 30, 0x1000)
    GUICtrlSetFont($Label_[($X + (($count +1)* .25))], 16)
    GUICtrlSetData($Label_[($X + (($count +1)* .25))], "00:00:00")
    $TButton_[($X + (($count +1)* .25))] = GUICtrlCreateButton("Start", $Left, $Top + 150, 50, 20)
    $SButton_[($X + (($count +1)* .25))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 150, 50, 20)
    $Input_[($X + (($count +1)* .25))] = GUICtrlCreateInput("", $Left, $Top + 170, 100, 20, 0x1000)
    
; row 3
    GUICtrlCreateLabel($Header_2 & " " & $X, $Left, $Top + 220, 100, 20, $SS_CENTER)
    $Label_[($X + (($count +1)* .5))] = GUICtrlCreateLabel("", $Left, $Top + 240, 100, 30, 0x1000)
    GUICtrlSetFont($Label_[($X + (($count +1)* .5))], 16)
    GUICtrlSetData($Label_[($X + (($count +1)* .5))], "00:00:00")
    $TButton_[($X + (($count +1)* .5))] = GUICtrlCreateButton("Start", $Left, $Top + 270, 50, 20)
    $SButton_[($X + (($count +1)* .5))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 270, 50, 20)
    $Input_[($X + (($count +1)* .5))] = GUICtrlCreateInput("", $Left, $Top + 290, 100, 20, 0x1000)
    
; row 4
   
    If ($X + (($count +1)* .75)) = ($count + 1) Then
        $Icon_1 = GUICtrlCreatePic($Toy_Banner, $Left, $Top + 360, 100, 50)
        GUICtrlSetState(-1, $GUI_DISABLE)
        ExitLoop
    EndIf
    GUICtrlCreateLabel($Header_3 & " " & $X, $Left, $Top + 340, 100, 20, $SS_CENTER)
    $Label_[($X + (($count +1)* .75))] = GUICtrlCreateLabel("", $Left, $Top + 360, 100, 30, 0x1000)
    GUICtrlSetFont($Label_[($X + (($count +1)* .75))], 16)
    GUICtrlSetData($Label_[($X + (($count +1)* .75))], "00:00:00")
    $TButton_[($X + (($count +1)* .75))] = GUICtrlCreateButton("Start", $Left, $Top + 390, 50, 20)
    $SButton_[($X + (($count +1)* .75))] = GUICtrlCreateButton("Stop", $Left + 50, $Top + 390, 50, 20)
    $Input_[($X + (($count +1)* .75))] = GUICtrlCreateInput("", $Left, $Top + 410, 100, 20, 0x1000)
    
    $Left = $Left + 110
Next

GUISetState()

While 1
    $msg = GUIGetMsg()
    
    For $xk = 1 To $count
        If $msg = $TButton_[$xk] And GUICtrlRead($Input_[$xk]) > "" Then
            GUICtrlSetState($TButton_[$xk], $GUI_DISABLE)
            GUICtrlSetState($Input_[$xk], $GUI_DISABLE)
            $TimerActive_[$xk] = 1
            $Timer_[$xk] = TimerInit()
        ElseIf $msg = $TButton_[$xk] Then
            MsgBox(64, "User Error:  " & $xk, "Please Type in a User Name   ", 3)
        EndIf
        If $msg = $SButton_[$xk] And GUICtrlRead($SButton_[$xk]) = "Reset" Then
            GUICtrlSetData($Label_[$xk], "00:00:00")
            GUICtrlSetData($Input_[$xk], "")
            GUICtrlSetData($SButton_[$xk], "Stop")
            GUICtrlSetState($TButton_[$xk], $GUI_ENABLE)
            GUICtrlSetState($Input_[$xk], $GUI_ENABLE)
        EndIf
        If $msg = $SButton_[$xk] And GUICtrlRead($Input_[$xk]) > "" And GUICtrlRead($SButton_[$xk]) = "Stop" Then
            $TimerActive_[$xk] = 0
            GUICtrlSetData($SButton_[$xk], "Reset")
            
       ;
            GUICtrlSetColor($Label_[$xk], 0x000000)
            $Name = GUICtrlRead($Input_[$xk])
       ;
            If $xk <= (($count +1)* .5) Then
                $Unit = $Header_1 & "  " & $xk
            EndIf
            If $xk > (($count +1)* .5) And $xk <= (($count +1)* .75) Then
                $Unit = $Header_2 & "   " & ($xk - (($count +1)* .5))
            EndIf
            If $xk > (($count +1)* .75) Then
                $Unit = $Header_3 & "   " & ($xk - (($count +1)* .75))
            EndIf
            RecordStuff()
        EndIf
    Next
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func AllTimers()
    Local $Secs, $Mins, $Hour
    For $ck = 1 To $count
        
        If $TimerActive_[$ck] Then
            _TicksToTime(Int(TimerDiff($Timer_[$ck])), $Hour, $Mins, $Secs)
            $Time_[$ck] = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
            If $sTime_[$ck] <> $Time_[$ck] Then GUICtrlSetData($Label_[$ck], $Time_[$ck])
            If $Mins > 29 Then GUICtrlSetColor($Label_[$ck], 0xff0000)
        EndIf
    Next
EndFunc ;==>AllTimers

Func RecordStuff()
    $LogStuff = FileOpen($Today_File, 1)
    FileWriteLine($LogStuff, "Station: " & $Unit & @CRLF)
    FileWriteLine($LogStuff, "User name: " & (GUICtrlRead($Input_[$xk])) & @CRLF)
    FileWriteLine($LogStuff, "Total time: " & (GUICtrlRead($Label_[$xk])) & @CRLF & @CRLF)
    FileClose($LogStuff)
    
EndFunc ;==>RecordStuff 

Func Setup()
$Set_win = GUICreate("   Toy BOX  -  Multi-Station-Timer", 350, 310)
GUISetIcon($Logo_icon)
$Icon_1 = GUICtrlCreatePic($Toy_Logo, 240, 10, 100, 250)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("3 Group Names", 10, 10, 220, 135)
$Head_1 = GUICtrlCreateInput($Header_1, 30, 40, 150, 20)
$Head_2 = GUICtrlCreateInput($Header_2, 30, 75, 150, 20)
$Head_3 = GUICtrlCreateInput($Header_3, 30, 110, 150, 20)
GUICtrlCreateGroup("Number of Timers", 10, 155, 220, 150)
$Note = GUICtrlCreateLabel("19 Total Timers", 30, 175, 150, 20, $SS_SUNKEN + $SS_CENTER  ) 
$Rad_[1] = GUICtrlCreateRadio("3", 40, 200, 30, 20)
$Rad_[2] = GUICtrlCreateRadio("7", 40, 220, 30, 20)
$Rad_[3] = GUICtrlCreateRadio("11", 40, 240, 30, 20)
$Rad_[4] = GUICtrlCreateRadio("15", 40, 260, 30, 20)
$Rad_[5] = GUICtrlCreateRadio("19", 40, 280, 30, 20)
GUICtrlSetState( -1, $GUI_CHECKED )
$Rad_[6] = GUICtrlCreateRadio("23", 140, 200, 30, 20)
$Rad_[7] = GUICtrlCreateRadio("27", 140, 220, 30, 20)
$Rad_[8] = GUICtrlCreateRadio("31", 140, 240, 30, 20)
$Rad_[9] = GUICtrlCreateRadio("35", 140, 260, 30, 20)
$Rad_[10] = GUICtrlCreateRadio("39", 140, 280, 30, 20)
$Create = GUICtrlCreateButton("Create", 250, 270, 80, 30)

GUISetState()

While 1
    $msg2 = GUIGetMsg()
    If $msg2 = $Create Then
        $Header_1 = GUICtrlRead($Head_1)
        $Header_2 = GUICtrlRead($Head_2)
        $Header_3 = GUICtrlRead($Head_3)
        For $tk = 1 to 10
            If GUICtrlRead($Rad_[$tk]) = $GUI_CHECKED Then
                $pk = $tk
                $Radx = $tk * 2 
                $count = (($tk * 4)-1)
                ExitLoop
            EndIf
        Next
        ExitLoop
    EndIf
    For $t = 1 to 10 
        If GUICtrlRead($Rad_[$t]) = $GUI_CHECKED Then
                GUICtrlSetData( $Note, (($t * 4)-1) & " Total Timers")
                ExitLoop
        EndIf
    Next    
    If $msg2 = $GUI_EVENT_CLOSE Then ExitLoop
    Sleep(70)
WEnd

GUIDelete($Set_win)
EndFunc

may help???

8)


NEWHeader1.png

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