Hallo zusammen,
da ich momentan von zwei CAD-Programmen die Geschwindigkeitsunterschiede messen soll, habe ich mir mit AutoIt eine kleine Stoppuhr gebastelt.
Nun wollte ich Euch fragen, was man am Code verbessern könnte. (Besserer Programmierstiel, einfachere Funktionen....)
Natürlich ist mir bewusst, dass jeder einen eigenen Programmierstiel hat. Doch ich finde meinen nicht wirklich gut im Moment.
Gut, ich fange erst an mit AutoIt und ich bin kein Programmierer!
Auch finde ich in diesem Beispiel unschön, dass ich Strings und Integer vermische.
Aber ich weiss nicht, wie ich sonst die Millisekunden auf HH : MM : SS . hh aufteilen könnte.
Wenn jemand konstruktive Ideen hat, dann nur her damit!
Danke!
Veronesi
Spoiler anzeigen
#include <WindowsConstants.au3>
#include <Date.au3>
Opt("GUIOnEventMode",1) ;Enable Interrupts for GUI
$GUI = GUICreate("Stoppuhr", 325, 126, 214, 139, 0x00080000, 0x00000008) ;Create GUI with Topmost ID
$Stoppuhr = GUICtrlCreateLabel("Stoppuhr", 8, 8, 135, 41)
GUICtrlSetFont(-1, 26, 400, 0, "Arial")
$Zeit = GUICtrlCreateLabel("00:00:00.00", 8, 56, 180, 41)
GUICtrlSetFont(-1, 26, 400, 0, "Arial")
GUICtrlSetColor(-1, 0xFF0000)
$StartStopp = GUICtrlCreateButton("Start", 225, 8, 89, 41, $WS_GROUP)
GUICtrlSetFont(-1, 16, 400, 0, "Arial")
$Reset = GUICtrlCreateButton("Reset", 225, 56, 89, 41, $WS_GROUP)
GUICtrlSetFont(-1, 16, 400, 0, "Arial")
GUICtrlSetOnEvent($StartStopp, "StartStopp") ;Create events for Buttons
GUICtrlSetOnEvent($Reset, "Reset")
GUISetOnEvent(-3, "End") ;Create Event for {ESC} and Close
GUISetState(@SW_SHOW) ;Show GUI
Dim $Start = False, $Timer = 0, $tmpTimer = 0, $LastTimer = 0
Dim $iHours, $iMins, $iSecs, $iHsecs
While Sleep(50) ;Main Loop
If $Start Then ;Only if start is pressed....
$tmpTimer = (TimerDiff($Timer)) + $LastTimer
Convert() ;Convert ticks to time and splitt it into HH:MM:SS.hh
GUICtrlSetData($Zeit, $iHours & ":" & $iMins & ":" &$iSecs & "." & $iHsecs) ;Update GUI
EndIf
WEnd
Func StartStopp() ;Interrupt for start/stop buttons
If $Start Then ;Stop button pressed
GUICtrlSetData($StartStopp, "Start") ;Change button text
$LastTimer = $tmpTimer
$Start = False
Convert() ;Convert ticks to time and splitt it into HH:MM:SS.hh
GUICtrlSetData($Zeit, $iHours & ":" & $iMins & ":" &$iSecs & "." & $iHsecs) ;Update GUI
Else
GUICtrlSetData($StartStopp, "Stopp") ;Start button pressed
$Start = True
$Timer = TimerInit()
EndIf
EndFunc ;==>StartStopp
Func Reset() ;Resets GUI
GUICtrlSetData($Zeit, "00:00:00.00")
$LastTimer = 0
$Timer = TimerInit()
EndFunc ;==>Reset
Func Convert() ;Convert ticks to time and splitt it into HH:MM:SS.hh
_TicksToTime($tmpTimer, $iHours, $iMins, $iSecs)
$iHsecs = StringRight($tmpTimer, 3)
$iHsecs = Round($iHsecs / 10)
If $iHours < 10 Then $iHours = "0" & $iHours
If $iMins < 10 Then $iMins = "0" & $iMins
If $iSecs < 10 Then $iSecs = "0" & $iSecs
If $iHsecs < 10 Then $iHsecs = "0" & $iHsecs
EndFunc ;==>Convert
Func End() ;Exit
Exit
EndFunc ;==>End