Back

Topic

[KB762]How to get/display the time with milliseconds using VBA

Tags: Scripting, VBA

10 years ago
By RM
Options
Print
Applies to:

All versions of PcVue


Summary:

There is nothing in VBA that will allow you to display the time with milliseconds. A simple solution is to call a system function.
Originator: NK


Details:

Private Type SYSTEMTIME
  wYear As Integer
  wMonth As Integer
  wDayOfWeek As Integer
  wDay As Integer
  wHour As Integer
  wMinute As Integer
  wSecond As Integer
  wMilliseconds As Integer
End Type

Private Declare Sub GetSystemTime Lib “kernel32”  (lpSystemTime As SYSTEMTIME)

Public Function TimeToMillisecond() As String
  Dim tSystem As SYSTEMTIME
  Dim sRet
  On Error Resume Next
  GetSystemTime tSystem
  sRet = Format(tSystem.wMilliseconds, “000”)
  TimeToMillisecond = sRet
End Function


Created on: 15 Apr 2015 Last update: 13 May 2024