Very often when we do logging for our script we would also want to apply a date/time stamp to them. Unfortunately VB does no offer any easy way to do this. This is how I do it:
LogFile = GetScriptPath() & "iStar_" & _ cStr(Year(now())) & Pad(cStr(Month(now())),2) & _ Pad(cStr(Day(now())),2) & Pad(cStr(Hour(now())),2) & _ Pad(cStr(Minute(now())),2) & Pad(cStr(Second(now())),2) & _ ".log"
You will see an additional function Pad(), this is necessary to ensure constant number of strings. The function simply added addition “0” for single digit numbers to make them 2 digits. It is of course a useful function for other stuff.
Function Pad(CStr2Pad, ReqStrLen) Dim Num2Pad Pad = CStr2Pad if len(CStr2Pad) < ReqStrLen then Num2Pad = string((ReqStrlen - len(CStr2Pad)), "0") Pad = Num2Pad & CStr2Pad end if End Function