Getting and Setting Time in VB.net

Chvrsri
Posted by Chvrsri under VB.NET category on | Points: 40 | Views : 3985
This is way to get the time using VB.net


I will illustrate this using an example function

Public Function GetTime() As String
Dim s As String
' Return time in HH:MM:SS format
s =Format(Hour,"00")& ":" & Format(Min, "00")& ":" _
& Format(Second, "00")
GetTime = s

End Function



This is way to set the time using VB.net in HH:MM:SS format


Public Sub SetTime(ByVal newtime As String)
Dim h As Integer
Dim m As Integer
Dim s As Integer

' input must be in HH:MM:SS format
' if values are invalid then raise INVALIDTIME event
h = CInt(Mid(newtime, 1, 2))
m = CInt(Mid(newtime, 4, 2))
s = CInt(Mid(newtime, 7, 2))
If h >= 0 And h <= 23 And m >= 0 And m <= 59 And s >= 0 And s <= 59 Then
mvarHour = h
mvarMin = m
mvarSecond = s
Else
RaiseEvent InvalidTime
End If
End Sub


If you could call these methods the job of getting and setting time will be done

cheers !!!

Comments or Responses

Login to post response