Prozentanzeigeformel für Variable Zeitangaben...

  • ...sry hab keine passende überschrift gefunden und wusste auch nicht recht zu googeln.
    Ich habe folgendes Problem. Der Benutzer gibt eine Zeit in Sekunden an in ein Inputfeld
    z.B. $Sleeptime = 10

    also 10000ms jetzt will ich, dass meine Prozentanzeige unabhängig davon mir immer
    den stand richtig ausgibt...

    [autoit]


    $SleepTimer = TimerInit()
    While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE then Exit
    Sleep(50)
    $SleepDiff = TimerDiff($SleepTimer)
    GUICtrlSetData($Progress,$SleepDiff/1000*$SleepTime) ;Hier hab ich keine Ahnung wie die ormal lauten muss
    If $SleepDiff > $SleepTime*1000 then
    msgbox(0,"",$SleepDiff)
    ExitLoop
    EndIf
    WEnd

    [/autoit]

    thx für hilfe :)

    • Offizieller Beitrag

    Prozentrechnung ;)

    [autoit]

    #include <GUIConstants.au3>
    #include <ProgressConstants.au3>

    [/autoit][autoit][/autoit][autoit]

    Local $SleepDiff, $SleepTime = 10 *1000

    [/autoit][autoit][/autoit][autoit]

    $gui = GUICreate('')
    $Progress = GUICtrlCreateProgress(10,10,200,20,$PBS_SMOOTH)
    $label = GUICtrlCreateLabel('', 220, 13, 40, 17)
    GUISetState()

    [/autoit][autoit][/autoit][autoit]

    $SleepTimer = TimerInit()
    While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $SleepDiff = 100 Then Exit
    $SleepDiff = TimerDiff($SleepTimer)/$SleepTime*100 ; Prozentrechnung ;)
    If $SleepDiff > 100 Then $SleepDiff = 100
    GUICtrlSetData($label, StringFormat("%0.2f %%", $SleepDiff) )
    GUICtrlSetData($Progress, $SleepDiff)
    WEnd

    [/autoit]
  • Ohne Gui mit Progressbar

    [autoit]


    $Sleeptime = 5 ;Sekunden
    $SleepTimer = TimerInit()

    [/autoit][autoit][/autoit][autoit]

    $ProgressFull = $Sleeptime * 1000 / 100
    ProgressOn("Vergangene Zeit","")
    While 1
    Sleep(50)
    $SleepDiff = TimerDiff($SleepTimer)
    ProgressSet($SleepDiff / $ProgressFull)
    If $SleepDiff >= $SleepTime*1000 Then
    ProgressOff()
    MsgBox(0,"",$SleepDiff)
    ExitLoop
    EndIf
    WEnd

    [/autoit]