![]() |
Tipp 0181
|
Mit Zeiten rechnen
|
 |
|
Autor/Einsender: Datum: |
|
R. Müller 28.12.2008 (Update) |
|
Entwicklungsumgebung: |
|
VB 6 |
|
|
Für Organigramme oder Zeiterfassungs-Programmen ist es oft notwendig mit Zeiten zu rechnen. Wie einfach dies
mit den VB-Funktionen Date und TimeSerial geht,
und ohne große Berechnungen anstellen zu müssen, zeigt dieser Tipp.
|
|
|
Dem Download liegt eine LED-Schrift bei, die in den Schriftenordner von Windows kopiert
werden muss.
|
|
|
Option Explicit
Dim dteSumme As Date
Private Sub chkMin_Click()
If chkMin.Value Then
'Anzeige: (MM)MM:SS
lblSumme.Caption = Format(dteSumme * 24 * 60, "00") & _
Format(dteSumme, ":ss")
Else
'Anzeige: (HH)HH:MM:SS
lblSumme.Caption = Format(Fix(dteSumme * 24), "00") & _
Format(dteSumme, ":nn:ss")
End If
End Sub
Private Sub cmdPlus_Click()
'Zeit addieren
dteSumme = dteSumme + TimeSerial(CInt(txtStunden.Text), _
CInt(txtMinuten.Text), CInt(txtSekunden.Text))
If chkMin.Value Then
'Anzeige: (MM)MM:SS
lblSumme.Caption = Format(dteSumme * 24 * 60, "00") & _
Format(dteSumme, ":ss")
Else
'Anzeige: (HH)HH:MM:SS
lblSumme.Caption = Format(Fix(dteSumme * 24), "00") & _
Format(dteSumme, ":nn:ss")
End If
End Sub
Private Sub cmdMinus_Click()
'Zeit subtrahieren
dteSumme = dteSumme - TimeSerial(CInt(txtStunden.Text), _
CInt(txtMinuten.Text), CInt(txtSekunden.Text))
If dteSumme < 0 Then dteSumme = 0 'Es gibt keine negative Zeit!
If chkMin.Value Then
'Anzeige: (MM)MM:SS
lblSumme.Caption = Format(dteSumme * 24 * 60, "00") & _
Format(dteSumme, ":ss")
Else
'Anzeige: (HH)HH:MM:SS
lblSumme.Caption = Format(Fix(dteSumme * 24), "00") & _
Format(dteSumme, ":nn:ss")
End If
End Sub
Private Sub cmdDelAll_Click()
'Alles löschen
txtStunden.Text = "00"
txtMinuten.Text = "00"
txtSekunden.Text = "00"
If chkMin.Value Then
lblSumme.Caption = "00:00"
Else
lblSumme.Caption = "00:00:00"
End If
dteSumme = 0
End Sub
Private Sub cmdBeenden_Click()
Unload Me
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set frmTimeCalc = Nothing
End Sub
'Bei GotFocus gesamten Text in Box markieren
Private Sub txtStunden_GotFocus()
txtStunden.SelStart = 0
txtStunden.SelLength = Len(txtStunden.Text)
End Sub
Private Sub txtMinuten_GotFocus()
txtMinuten.SelStart = 0
txtMinuten.SelLength = Len(txtMinuten.Text)
End Sub
Private Sub txtSekunden_GotFocus()
txtSekunden.SelStart = 0
txtSekunden.SelLength = Len(txtSekunden.Text)
End Sub
|
|
|
|
|
Windows-Version |
95 |
 |
|
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
VB-Version |
VBA 5 |
 |
|
VBA 6 |
 |
|
VB 4/16 |
 |
|
VB 4/32 |
 |
|
VB 5 |
 |
|
VB 6 |
 |
|
|
|
Download (6
kB)
|
Downloads bisher: [ 4294 ]
|
|
|