Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Snippet] Get OS Uptime
#1
[Image: mM540.png]

Full Codes:
Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, _
                           ByVal e As System.EventArgs) _
                           Handles MyBase.Load

        Timer1.Enabled = True
        Timer1.Interval = 10
        Timer1.Start()
    End Sub

    Sub Timer1_Tick() Handles Timer1.Tick
        TextBox1.Text = GetOSUptime()
    End Sub

    Private Shared Function GetOSUptime() As String
        'Gets the number of milliseconds elapsed since the system started in minutes.

        Dim intDays As Integer
        Dim intHours As Integer
        Dim intMinutes As Integer
        Dim intSeconds As Integer
        Dim intRemainder As Integer
        Dim intTicks As Integer

        ' initialize string variables
        Dim strDays As String = ""
        Dim strHours As String = ""
        Dim strMinutes As String = ""
        Dim strSeconds As String = ""

        Try
            ' updates tick counter intTicks
            intTicks = System.Environment.TickCount

            ' there are  86400000 milliseconds in one day,
            ' 'compute whole days and get remainder
            Do
                intDays = Int(intTicks \ 86400000)
                intRemainder = intTicks Mod 86400000
            Loop Until intRemainder <= 86400000

            ' there are 3600000 milliseconds in one hour,
            ' 'compute whole hours and get remainder
            Do
                intHours = Int(intRemainder \ 3600000)
                intRemainder = intRemainder Mod 3600000
            Loop Until intRemainder <= 3600000

            ' there are 60000 milliseconds in one minute,
            ' compute whole minutes and get remainder
            Do
                intMinutes = Int(intRemainder \ 60000)
                intRemainder = intRemainder Mod 60000
            Loop Until intRemainder <= 60000

            ' there are 1000 milliseconds in one second,
            ' compute whole seconds and get remainder
            Do
                intSeconds = Int(intRemainder \ 1000)
                intRemainder = intRemainder Mod 1000
            Loop Until intRemainder <= 1000

            ' format days
            If intDays = 0 Then
                strDays = ""
            ElseIf Trim(CStr(intDays)).Length = 1 Then
                strDays = String.Format(" {0}:", Trim(CStr(intDays)))
            ElseIf Trim(CStr(intDays)).Length = 2 Then
                strDays = Trim(CStr(intDays)) & ":"
            End If

            ' format hours
            If intHours = 0 And intDays = 0 Then
                strHours = ""
            ElseIf Trim(CStr(intHours)).Length = 1 Then
                strHours = String.Format("0{0}:", Trim(CStr(intHours)))
            ElseIf Trim(CStr(intHours)).Length = 2 Then
                strHours = Trim(CStr(intHours)) & ":"
            End If

            ' format minutes
            If intMinutes = 0 Then
                strMinutes = "00" & ":"
            ElseIf Trim(CStr(intMinutes)).Length = 1 Then
                strMinutes = String.Format("0{0}:", Trim(CStr(intMinutes)))
            ElseIf Trim(CStr(intMinutes)).Length = 2 Then
                strMinutes = Trim(CStr(intMinutes)) & ":"
            End If

            ' format seconds
            If intSeconds = 0 Then
                strSeconds = "00"
            ElseIf Trim(CStr(intSeconds)).Length = 1 Then
                strSeconds = "0" & Trim(CStr(intSeconds))
            ElseIf Trim(CStr(intSeconds)).Length = 2 Then
                strSeconds = Trim(CStr(intSeconds))
            End If

            ' return time string
            Return strDays & strHours & strMinutes & strSeconds
        Catch ex As Exception
            Return ""
        End Try
    End Function

End Class
USB Anti-virus? Try USB Drive Defender
[Image: 8bQCusS.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Snippet] Autoclose Msgbox euverve 7 3,285 05-25-2011, 06:41 PM
Last Post: Pyratepig
  [Snippet] Check Email if gmail and valid password length euverve 4 1,815 05-20-2011, 06:51 AM
Last Post: stephen5565
  [Snippet] Get Local Getway euverve 1 1,026 05-16-2011, 07:56 PM
Last Post: KoBE
  [Snippet] Random pick from list (Range) euverve 0 692 05-12-2011, 08:22 AM
Last Post: euverve
  Help with Snippet/paint. Aero 5 1,578 05-05-2011, 12:25 PM
Last Post: iCrack

Forum Jump:


Users browsing this thread: 1 Guest(s)