Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

GetBatteryTime - Get the life time of a notebook's battery
[ All Languages » VB »  Windows]

Total Hit ( 1954)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Private Declare Function GetSystemPowerStatus Lib "kernel32" _
  (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long

Private Type SYSTEM_POWER_STATUS
    ACLineStatus As Byte
    BatteryFlag As Byte
    BatteryLifePercent As Byte
    Reserved1 As Byte
    BatteryLifeTime As Long
    BatteryFullLifeTime As Long
End 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 If

End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.