Jump to content

Stuck in making a loop


Lempke
 Share

Recommended Posts

I am trying to make a punchcard system (hope that this is the correct word) but I am stuck on making it so I don't have to write the code over and aover again.

I can write the same code 4 times but there has to be a more efficient methode.

can somebody help me / put me in the right direction?

This is what I have so far.

#include <GuiConstants.au3>

Opt("TrayIconDebug", 1)
Opt("GUIOnEventMode", 1)

Dim $Name[5]
Dim $Btn_Name[5]
Dim $Count[5]
Dim $Lbl_Name[5]
Dim $Lbl_Time[5][5]
Dim $Btn_Exit

$Name[1] = "Steve"
$Name[2] = "Chris"
$Name[3] = "John"
$Name[4] = "Bob"


;------------------------------------------------- GUI ------------------------------------------------------------

GUICreate("Uren " & $Version, 1000, 800)
GuiSetIcon(@SystemDir & "\shell32.dll", 111)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")

$Btn_Exit = GUICtrlCreateButton( "Exit", 250, 140, 60, 20)
GUICtrlSetOnEvent($Btn_Exit, "Quit")

$Btn_Name[1] = GUICtrlCreateButton("", 10, 10, 20, 20)
$Lbl_Name[1] = GUICtrlCreateLabel($Name[1], 40, 15, 100, 20)
GUICtrlSetState($Lbl_Name[1], $GUI_DISABLE)
GUICtrlSetOnEvent($Btn_Name[1], "Name1")

$Lbl_Time[1][1] = GuiCtrlCreateInput("", 200, 10, 40, 20)
$Lbl_Time[1][2] = GuiCtrlCreateInput("", 260, 10, 40, 20)
$Lbl_Time[1][3] = GuiCtrlCreateInput("", 320, 10, 40, 20)
$Lbl_Time[1][4] = GuiCtrlCreateInput("", 380, 10, 40, 20)

GUISetState()

While 1
    Sleep(50)
WEnd


;------------------------------------------------- FUNCTIONS ------------------------------------------------------

Func Name1()
    
    Select
        Case $Count[1] = 0
            GUICtrlSetData($Lbl_Time[1][1], @HOUR & "," & @MIN)
            GUICtrlSetState($Lbl_Name[1], $GUI_ENABLE)
        Case $Count[1] = 1
            GUICtrlSetData($Lbl_Time[1][2], @HOUR & "," & @MIN)
            GUICtrlSetState($Lbl_Name[1], $GUI_DISABLE)
        Case $Count[1] = 2
            GUICtrlSetData($Lbl_Time[1][3], @HOUR & "," & @MIN)
            GUICtrlSetState($Lbl_Name[1], $GUI_ENABLE)
        Case $Count[1] = 3
            GUICtrlSetData($Lbl_Time[1][4], @HOUR & "," & @MIN)
            GUICtrlSetState($Lbl_Name[1], $GUI_DISABLE)
    EndSelect
    $Count[1] = $Count[1] + 1
    Return
EndFunc


Func Quit()
    Exit
EndFunc
Link to comment
Share on other sites

How about this:

Func Name1()
  if $Count[1] <= 3 then
    GUICtrlSetData($Lbl_Time[1][$Count[1] + 1], @HOUR & "," & @MIN)
    GUICtrlSetState($Lbl_Name[1], $GUI_ENABLE)
  endif
  $Count[1] += 1
EndFunc
Thx for the input, but that is not exactly what I had in mind.

I created a script for one person with one button. I need like 30 persons eventually. I was trying to get it working for four persons and then go from there, but I don't know how.

Do I have to write the script 30 times with 30 buttons and 120 input fields or can I use some kind of loop? I think my main problem is that I don't know wich button is pressed bij which user.

My goal is, that when somebody starts working he or she clicks a button and the time is saved, same thing for the break and the end of the day. 4 times in total.

Link to comment
Share on other sites

Thx for the input, but that is not exactly what I had in mind.

I created a script for one person with one button. I need like 30 persons eventually. I was trying to get it working for four persons and then go from there, but I don't know how.

Do I have to write the script 30 times with 30 buttons and 120 input fields or can I use some kind of loop? I think my main problem is that I don't know wich button is pressed bij which user.

My goal is, that when somebody starts working he or she clicks a button and the time is saved, same thing for the break and the end of the day. 4 times in total.

hmm, perhaps you should think about another idea to avoid that you have to create 30 buttons.

when you do it that way, also every user can click every button and change times from other users.

you can do it with just one button if you use the @username variable when someone clicks the button

. for that method it is necessary that every user logs in with his own account. if all users work under the same account you can do it with a password inputfield which looks in perhaps a textfile which is encrypted to check that the users can just lock their own time.

when i have time later i can gibe you an example of what i mean.

greets, sirhc

Link to comment
Share on other sites

hmm, perhaps you should think about another idea to avoid that you have to create 30 buttons.

I would like to start the same function, but depending on the button that is pushed. Use a Variable in the name of a Variable

when you do it that way, also every user can click every button and change times from other users.

you can do it with just one button if you use the @username variable when someone clicks the button

. for that method it is necessary that every user logs in with his own account. if all users work under the same account you can do it with a password inputfield which looks in perhaps a textfile which is encrypted to check that the users can just lock their own time.

when i have time later i can gibe you an example of what i mean.

greets, sirhc

The idea was to run it on a single pc that is already logged on. It is true that anyone can change any time, but that is a problem for later on. At this moment we use a pease of paper where we write down the times and then somebody has to type all the values into an Excel sheet. (how modern and automated is that :"> )

I want to translate this paper and the manual work to a script in AutoIt (personal challange, trying to get better in AutoIt :) )

I thought that I kept it simple enough but I was wrong...

Finetuning is for later worries

Edited by Lempke
Link to comment
Share on other sites

Thx for the input, but that is not exactly what I had in mind.

I created a script for one person with one button. I need like 30 persons eventually. I was trying to get it working for four persons and then go from there, but I don't know how.

Do I have to write the script 30 times with 30 buttons and 120 input fields or can I use some kind of loop? I think my main problem is that I don't know wich button is pressed bij which user.

My goal is, that when somebody starts working he or she clicks a button and the time is saved, same thing for the break and the end of the day. 4 times in total.

Well, you asked for a script that prevented you from writing the same code 4 times, which is what I gave you. Maybe you didn't get the right answer because you didn't ask the right question. :)

The problem you're having doesn't have anything to do with loops or repeating sections of code. You're struggling with a design issue. Having 30 buttons and 120 input fields on an application is, well, just wrong. As others have already pointed out, you need to scrap the button idea and look at a much simplier GUI. The time card systems that I've done in the past have always had the user log in with a username/password and then "punch" in/out.

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Well, you asked for a script that prevented you from writing the same code 4 times, which is what I gave you. Maybe you didn't get the right answer because you didn't ask the right question. :)

The problem you're having doesn't have anything to do with loops or repeating sections of code. You're struggling with a design issue. Having 30 buttons and 120 input fields on an application is, well, just wrong. As others have already pointed out, you need to scrap the button idea and look at a much simplier GUI. The time card systems that I've done in the past have always had the user log in with a username/password and then "punch" in/out.

I guess that makes sense...sirhc did point that out as well.

My first idea was to translate the paper we use without modifying it to much. But maybe I have to rethink my design. I tought that it would be a nice challenge, but it turns out its not that efficient.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...