GetBatteryTime – Get the life time of a notebook’s battery

GetBatteryTime – Get the life time of a notebook’s battery

Private Declare Function GetSystemPowerStatus Lib "kernel32" _    (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As LongPrivate Type SYSTEM_POWER_STATUS        ACLineStatus As Byte        BatteryFlag As Byte        BatteryLifePercent As Byte        Reserved1 As Byte        BatteryLifeTime As Long        BatteryFullLifeTime As LongEnd Type' Get the life time of a notebook's battery.' Returns -1 if the computer is not a notebook or if it's not using a battery' Param values:'   0 -> return the lifetime in seconds (by default)'   1 -> return the lifetime in minutes'   2 -> return the lifetime in hours' Example:'   MsgBox "Left minutes:" & GetBatteryTime(1)Private Function GetBatteryTime(Optional ByVal ResultFormat As Integer) As _    Double    Dim SysStatus As SYSTEM_POWER_STATUS    GetSystemPowerStatus SysStatus        ' return the number of seconds    If ResultFormat = 0 Then        GetBatteryTime = SysStatus.BatteryLifeTime    ' return the number of minutes    ElseIf ResultFormat = 1 Then        GetBatteryTime = SysStatus.BatteryLifeTime / 60    ' return the number of hours    Else        GetBatteryTime = SysStatus.BatteryLifeTime / 3600    End IfEnd Function

See also  5 Benefits of Using Time Tracking Software

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist