Post by James Grubbs (Jimmy) on Apr 23, 2019 0:34:15 GMT -5
Just playing around and thought I would share. I don't even know if there is any use for this Function.
'Custom Time String Function
'Created By James Grubbs
'Acceptable switches
' "f" change to 12 hour format
' "-h" remove hour
' "-m" remove minutes
' "-s" remove seconds
' "-c" remove colons
' "-r" remove spaces
' "a" add Meridiem (AM/PM)
'MUST PUT A SPACE between switches however the switches can be placed in any order
'Ex. Using switches "f a -s" Changes to 12 hour format, adds merideim and removes seconds
YourVariableNameHere$ = ChangeTimeFormat$(GetNewTimeFormat$, "f a -s");GetNewTimeFormat$
PRINT GetNewTimeFormat$
'OR
PRINT YourVariableNameHere$
wait
FUNCTION ChangeTimeFormat$(BYREF CustomTimeFormat$, FormatSwitches$)
FormatSwitches$=LOWER$(FormatSwitches$)
SwitchList$ = "f -h -m -s a -c -r"
CountUserSwitches = 1
WHILE WORD$(FormatSwitches$, CountUserSwitches) <> ""
CountUserSwitches=CountUserSwitches + 1
WEND
CountUserSwitches=CountUserSwitches - 1
FOR switchLoop = 1 TO 7
FOR userSwitchCNT = 1 TO CountUserSwitches
IF WORD$(FormatSwitches$, userSwitchCNT) = WORD$(SwitchList$, switchLoop) THEN
tempFS$ = tempFS$+WORD$(FormatSwitches$, userSwitchCNT) + " "
AddMe2Str = 1
EXIT FOR
ELSE
AddMe2Str = 0
END IF
NEXT userSwitchCNT
IF AddMe2Str = 0 THEN tempFS$=tempFS$+"**"+" "
AddMe2Str = 0
NEXT switchLoop
FormatSwitches$ = tempFS$
Hour$ = LEFT$(TIME$(), 3)
IF WORD$(FormatSwitches$, 1) = "f" AND val(Hour$) > 12 THEN Hour$ = STR$(VAL(Hour$) - 12)+":"
IF WORD$(FormatSwitches$, 1) = "f" AND val(Hour$) = 00 THEN Hour$ = "12:"
Minutes$ = MID$(TIME$(), 4, 3)
Seconds$ = RIGHT$(TIME$(), 2)
CustomTimeFormat$ = Hour$ + Minutes$ + Seconds$
IF WORD$(FormatSwitches$, 2) = "-h" THEN Hour$ = ""
IF WORD$(FormatSwitches$, 3) = "-m" THEN Minutes$ = ""
IF WORD$(FormatSwitches$, 4) = "-s" THEN Seconds$ = ""
CustomTimeFormat$ = Hour$ + Minutes$ + Seconds$
IF RIGHT$(CustomTimeFormat$, 1) = ":" THEN CustomTimeFormat$=LEFT$(CustomTimeFormat$, LEN(CustomTimeFormat$)-1)
IF WORD$(FormatSwitches$, 5) = "a" AND VAL(TIME$()) > 12 THEN CustomTimeFormat$ = CustomTimeFormat$ + " PM"
IF WORD$(FormatSwitches$, 5) = "a" AND VAL(TIME$()) < 13 THEN CustomTimeFormat$ = CustomTimeFormat$ + " AM"
IF WORD$(FormatSwitches$, 6) = "-c" THEN CustomTimeFormat$ = REPLSTR$(CustomTimeFormat$, ":", " ")
IF WORD$(FormatSwitches$, 7) = "-r" THEN CustomTimeFormat$ = REMCHAR$(CustomTimeFormat$, " ")
END FUNCTION