Results 1 to 6 of 6

Thread: Computer UP Time. {RESOLVED}

Threaded View

  1. #1

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up Computer UP Time. {RESOLVED}

    OK I wrote this code to show me how long my computer is been on for. Now I just want to know that if someone can modify this make this smaller and more efficient. It's VB.NET btw.

    Cheers.

    VB Code:
    1. Imports System.Environment
    2.  
    3. Private Sub Show_PCUp_Time()
    4.        Dim strDisplay As String
    5.        Dim SecondValue As Double
    6.        Dim TMP1 As Double
    7.        Dim TMP2 As Double
    8.        Dim TMP3 As Double
    9.        Dim Days As Integer
    10.        Dim Hours As Integer
    11.        Dim Minutes As Integer
    12.        Dim Seconds As Integer
    13.  
    14.        Dim str1 As String
    15.        Dim str2 As String
    16.        Dim str3 As String
    17.        Dim str4 As String
    18.  
    19.        Dim strSub As String
    20.  
    21.        SecondValue = Format(TickCount / 1000, "0")
    22.  
    23.        Days = Math.Floor(SecondValue / 86400)
    24.        If Days > 0 Then
    25.            TMP1 = SecondValue - (Days * 86400)
    26.        Else
    27.            TMP1 = SecondValue
    28.        End If
    29.  
    30.        Hours = Math.Floor(TMP1 / 3600)
    31.        If Hours > 0 Then
    32.            TMP2 = TMP1 - (Hours * 3600)
    33.        Else
    34.            TMP2 = TMP1
    35.        End If
    36.  
    37.        Minutes = Math.Floor(TMP2 / 60)
    38.        If Minutes > 0 Then
    39.            TMP3 = TMP2 - (Minutes * 60)
    40.        Else
    41.            TMP3 = TMP2
    42.        End If
    43.  
    44.        Seconds = Math.Floor(TMP3)
    45.  
    46.        If Days > 0 And Days < 1 Then
    47.            str1 = CStr(Days) & " Day"
    48.        Else
    49.            If Days > 1 Then
    50.                str1 = CStr(Days) & " Days"
    51.            Else
    52.                str1 = " "
    53.            End If
    54.        End If
    55.  
    56.        If Hours > 0 And Hours < 1 Then
    57.            str2 = CStr(Hours) & " Hour"
    58.        Else
    59.            If Hours > 1 Then
    60.                str2 = CStr(Hours) & " Hours"
    61.            Else
    62.                str2 = " "
    63.            End If
    64.        End If
    65.  
    66.        If Minutes > 0 And Minutes < 1 Then
    67.            str3 = CStr(Minutes) & " Minute"
    68.        Else
    69.            If Minutes > 1 Then
    70.                str3 = CStr(Minutes) & " Minutes"
    71.            Else
    72.                str3 = " "
    73.            End If
    74.        End If
    75.  
    76.        If Seconds > 0 And Seconds < 1 Then
    77.            str4 = CStr(Seconds) & " Second"
    78.        Else
    79.            If Seconds > 1 Then
    80.                str4 = CStr(Seconds) & " Seconds"
    81.            Else
    82.                str4 = " "
    83.            End If
    84.        End If
    85.  
    86.        strDisplay = str1 & ", " & str2 & ", " & str3 & ", " & str4 & " "
    87.        strDisplay = Trim(Replace(strDisplay, ",  ", " "))
    88.  
    89.        strSub = Microsoft.VisualBasic.Left(strDisplay, 1)
    90.        If strSub = "," Then
    91.            strDisplay = Microsoft.VisualBasic.Right(strDisplay, Len(strDisplay) - 1)
    92.        End If
    93.  
    94.        strSub = Microsoft.VisualBasic.Left(strDisplay, 1)
    95.        If strSub = "," Then
    96.            strDisplay = Microsoft.VisualBasic.Right(strDisplay, Len(strDisplay) - 1)
    97.        End If
    98.  
    99.        strSub = Microsoft.VisualBasic.Left(strDisplay, 1)
    100.        If strSub = "," Then
    101.            strDisplay = Microsoft.VisualBasic.Right(strDisplay, Len(strDisplay) - 1)
    102.        End If
    103.  
    104.        strSub = Microsoft.VisualBasic.Left(strDisplay, 1)
    105.        If strSub = "," Then
    106.            strDisplay = Microsoft.VisualBasic.Right(strDisplay, Len(strDisplay) - 1)
    107.        End If
    108.  
    109.        strDisplay = Replace(strDisplay, "s ,", "s,")
    110.        strDisplay = Replace(strDisplay, "y ,", "y,")
    111.        strDisplay = Replace(strDisplay, "r ,", "r,")
    112.        strDisplay = Replace(strDisplay, "e ,", "e,")
    113.        strDisplay = Replace(strDisplay, "d ,", "d,")
    114.  
    115.        MsgBox(strDisplay)
    116. End Sub
    Last edited by wrack; Sep 25th, 2003 at 05:01 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width