Gemeinsam zu mehr Effizienz in der Anwendungserstellung
K |
K |
||
Zeile 19: | Zeile 19: | ||
Else | Else | ||
FormatString = Replace(FormatString, "[hh]", "[h]", , , vbTextCompare) | FormatString = Replace(FormatString, "[hh]", "[h]", , , vbTextCompare) | ||
- | FormatString = Replace(FormatString, "[h]", Replace(CStr(Hours), 0, "\0"), , , vbTextCompare) | + | FormatString = Replace(FormatString, "[h]", Replace(CStr(Hours), "0", "\0"), , , vbTextCompare) |
End If | End If | ||
End If | End If |
Für die formatierte Ausgabe eines Datum/Zeit-Wertes (Date-Datentyp) von mehr als 24 Stunden könnte man die Format-Funktion überschreiben und die Syntax von Excel nutzen.
Beispiel: Format(Timeserial(60,30,15), "[hh]:nn:ss")
Public Function Format(ByVal Expression As Variant, Optional ByVal FormatString As Variant, _ Optional ByVal FirstDayOfWeek As VbDayOfWeek = vbSunday, _ Optional ByVal FirstWeekOfYear As VbFirstWeekOfYear = vbFirstJan1) As String Dim Hours As Long If IsDate(Expression) Then If InStr(1, FormatString, "[h", vbTextCompare) > 0 Then Hours = Fix(Round(CDate(Expression) * 24, 1)) If Hours < 24 Then FormatString = Replace(FormatString, "[hh]", "hh", , , vbTextCompare) FormatString = Replace(FormatString, "[h]", "h", , , vbTextCompare) Else FormatString = Replace(FormatString, "[hh]", "[h]", , , vbTextCompare) FormatString = Replace(FormatString, "[h]", Replace(CStr(Hours), "0", "\0"), , , vbTextCompare) End If End If End If Format = VBA.Format$(Expression, FormatString, FirstDayOfWeek, FirstWeekOfYear) End Function