Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Redundancy at its finest

Redundancy at its finest

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpvisual-studioquestion
10 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Edward Giles
    wrote on last edited by
    #1

    I found this code in the My.Power extension for Visual Studio:

    Public ReadOnly Property BatteryPercent()
    ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
    Get
    If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
    Return "100%"
    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
    Return "99%"
    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
    Return "98%"
    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
    Return "97%"
    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
    Return "96%"

    ...

                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
                    Return "6%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
                    Return "5%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
                    Return "4%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
                    Return "3%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
                    Return "2%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
                    Return "1%"
                Else
                    Return "NA"
                End If
            End Get
        End Property
    

    What idiot would write this? How about:

    If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
    SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
    IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
    Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
    Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
    Return "NA"
    Else
    Return FormatNumber(SystemInformation.PowerSta

    Kornfeld Eliyahu PeterK B B OriginalGriffO Z 7 Replies Last reply
    0
    • E Edward Giles

      I found this code in the My.Power extension for Visual Studio:

      Public ReadOnly Property BatteryPercent()
      ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
      Get
      If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
      Return "100%"
      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
      Return "99%"
      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
      Return "98%"
      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
      Return "97%"
      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
      Return "96%"

      ...

                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
                      Return "6%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
                      Return "5%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
                      Return "4%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
                      Return "3%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
                      Return "2%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
                      Return "1%"
                  Else
                      Return "NA"
                  End If
              End Get
          End Property
      

      What idiot would write this? How about:

      If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
      SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
      IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
      Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
      Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
      Return "NA"
      Else
      Return FormatNumber(SystemInformation.PowerSta

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      Don't call him idiot! He had a bad day week year decade! (And he didn't published it on VS Galery...)

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      1 Reply Last reply
      0
      • E Edward Giles

        I found this code in the My.Power extension for Visual Studio:

        Public ReadOnly Property BatteryPercent()
        ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
        Get
        If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
        Return "100%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
        Return "99%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
        Return "98%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
        Return "97%"
        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
        Return "96%"

        ...

                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
                        Return "6%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
                        Return "5%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
                        Return "4%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
                        Return "3%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
                        Return "2%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
                        Return "1%"
                    Else
                        Return "NA"
                    End If
                End Get
            End Property
        

        What idiot would write this? How about:

        If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
        SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
        IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
        Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
        Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
        Return "NA"
        Else
        Return FormatNumber(SystemInformation.PowerSta

        B Offline
        B Offline
        Brisingr Aerowing
        wrote on last edited by
        #3

        I guess that coder works for the Department Of Redundancy Department. I wonder if the Government of the US Government has a Department Of Redundancy Department. It sure seems like a lot of things come from there.

        Keep Clam And Proofread -- √(-1) 23 ∑ π... And it was delicious.

        Z 1 Reply Last reply
        0
        • E Edward Giles

          I found this code in the My.Power extension for Visual Studio:

          Public ReadOnly Property BatteryPercent()
          ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
          Get
          If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
          Return "100%"
          ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
          Return "99%"
          ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
          Return "98%"
          ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
          Return "97%"
          ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
          Return "96%"

          ...

                      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
                          Return "6%"
                      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
                          Return "5%"
                      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
                          Return "4%"
                      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
                          Return "3%"
                      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
                          Return "2%"
                      ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
                          Return "1%"
                      Else
                          Return "NA"
                      End If
                  End Get
              End Property
          

          What idiot would write this? How about:

          If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
          SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
          IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
          Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
          Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
          Return "NA"
          Else
          Return FormatNumber(SystemInformation.PowerSta

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Great code. SystemInformation.PowerStatus.BatteryLifePercent is a float. And if the battery is empty, he'll say it's not available...

          E 1 Reply Last reply
          0
          • E Edward Giles

            I found this code in the My.Power extension for Visual Studio:

            Public ReadOnly Property BatteryPercent()
            ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
            Get
            If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
            Return "100%"
            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
            Return "99%"
            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
            Return "98%"
            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
            Return "97%"
            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
            Return "96%"

            ...

                        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
                            Return "6%"
                        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
                            Return "5%"
                        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
                            Return "4%"
                        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
                            Return "3%"
                        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
                            Return "2%"
                        ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
                            Return "1%"
                        Else
                            Return "NA"
                        End If
                    End Get
                End Property
            

            What idiot would write this? How about:

            If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
            SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
            IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
            Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
            Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
            Return "NA"
            Else
            Return FormatNumber(SystemInformation.PowerSta

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            :doh: The idiot! That should so obviously be a Select Case... :laugh:

            The only instant messaging I do involves my middle finger.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            • B Brisingr Aerowing

              I guess that coder works for the Department Of Redundancy Department. I wonder if the Government of the US Government has a Department Of Redundancy Department. It sure seems like a lot of things come from there.

              Keep Clam And Proofread -- √(-1) 23 ∑ π... And it was delicious.

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #6

              Wow, you can say that again. :)

              There are only 10 types of people in the world, those who understand binary and those who don't.

              1 Reply Last reply
              0
              • E Edward Giles

                I found this code in the My.Power extension for Visual Studio:

                Public ReadOnly Property BatteryPercent()
                ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
                Get
                If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
                Return "100%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
                Return "99%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
                Return "98%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
                Return "97%"
                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
                Return "96%"

                ...

                            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
                                Return "6%"
                            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
                                Return "5%"
                            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
                                Return "4%"
                            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
                                Return "3%"
                            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
                                Return "2%"
                            ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
                                Return "1%"
                            Else
                                Return "NA"
                            End If
                        End Get
                    End Property
                

                What idiot would write this? How about:

                If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
                SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
                IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
                Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
                Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
                Return "NA"
                Else
                Return FormatNumber(SystemInformation.PowerSta

                Z Offline
                Z Offline
                ZurdoDev
                wrote on last edited by
                #7

                Good thing the battery can't give 110% like some developers do. :)

                There are only 10 types of people in the world, those who understand binary and those who don't.

                1 Reply Last reply
                0
                • E Edward Giles

                  I found this code in the My.Power extension for Visual Studio:

                  Public ReadOnly Property BatteryPercent()
                  ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
                  Get
                  If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
                  Return "100%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
                  Return "99%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
                  Return "98%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
                  Return "97%"
                  ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
                  Return "96%"

                  ...

                              ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
                                  Return "6%"
                              ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
                                  Return "5%"
                              ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
                                  Return "4%"
                              ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
                                  Return "3%"
                              ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
                                  Return "2%"
                              ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
                                  Return "1%"
                              Else
                                  Return "NA"
                              End If
                          End Get
                      End Property
                  

                  What idiot would write this? How about:

                  If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
                  SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
                  IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
                  Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
                  Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
                  Return "NA"
                  Else
                  Return FormatNumber(SystemInformation.PowerSta

                  0 Offline
                  0 Offline
                  0bx
                  wrote on last edited by
                  #8

                  I wonder what he would have done if they suddenly wanted to display the battery life at 0.1% accuracy...

                  .

                  1 Reply Last reply
                  0
                  • E Edward Giles

                    I found this code in the My.Power extension for Visual Studio:

                    Public ReadOnly Property BatteryPercent()
                    ' This code will retrieve the BatteryLifePercent property and convert it to a percent.
                    Get
                    If SystemInformation.PowerStatus.BatteryLifePercent.ToString = "1" Then
                    Return "100%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.99" Then
                    Return "99%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.98" Then
                    Return "98%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.97" Then
                    Return "97%"
                    ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.96" Then
                    Return "96%"

                    ...

                                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.06" Then
                                    Return "6%"
                                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.05" Then
                                    Return "5%"
                                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.04" Then
                                    Return "4%"
                                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.03" Then
                                    Return "3%"
                                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.02" Then
                                    Return "2%"
                                ElseIf SystemInformation.PowerStatus.BatteryLifePercent.ToString = "0.01" Then
                                    Return "1%"
                                Else
                                    Return "NA"
                                End If
                            End Get
                        End Property
                    

                    What idiot would write this? How about:

                    If SystemInformation.PowerStatus.BatteryLifePercent <= 0 OrElse _
                    SystemInformation.PowerStatus.BatteryLifePercent > 1 OrElse _
                    IsNothing(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
                    Single.IsNaN(SystemInformation.PowerStatus.BatteryLifePercent) OrElse _
                    Single.IsInfinity(SystemInformation.PowerStatus.BatteryLifePercent) Then
                    Return "NA"
                    Else
                    Return FormatNumber(SystemInformation.PowerSta

                    M Offline
                    M Offline
                    MacSpudster
                    wrote on last edited by
                    #9

                    An idiot did not write this, for I'm sure they used copy/paste to comprise most of it with assistance from type-ahead. ;P Besides, being the float that it is, he merely wanted to float himself more hours to enable himself to float (er, buy a boat) on the lake. Thus, he used the float associatively correct.

                    1 Reply Last reply
                    0
                    • B Bernhard Hiller

                      Great code. SystemInformation.PowerStatus.BatteryLifePercent is a float. And if the battery is empty, he'll say it's not available...

                      E Offline
                      E Offline
                      Edward Giles
                      wrote on last edited by
                      #10

                      Is the VB.NET equivalent of a float a Double (64-bit float) or a Single (32-bit float)?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups