Re: Getting a battery level
Re: Getting a battery level
Thanks. I shoudl be able to use a Dim/Private/similar to create this control in a class module, right? There are no forms in this since it's a DLL >_>
Re: Getting a battery level
I believe you should be able to. :thumb:
Good luck with your project.
Re: Getting a battery level
Thanks. I am having some problems though...
Option Explicit
Public Function main()
Dim Sys As SysInfoLib.SysInfo
main = Sys.BatteryLifePercent <- this line creates the error below
End Function
Creates run-time error 91, "Object Variable or With Block not set." This is in a class module. I've tried adding "New" in there, but that just tells me it's an improper use of the new keyword. Is there anything you can see that I'm doing wrong?
Re: Getting a battery level
Try this
Code:
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
Private Sub Command1_Click()
Dim MyStatus As SYSTEM_POWER_STATUS
Dim MyLifeTime As Double
GetSystemPowerStatus MyStatus
MyLifeTime = MyStatus.BatteryLifeTime
If MyLifeTime = -1 Then
MsgBox "Using AC Power"
Else
MsgBox "I have " & MyLifeTime / 3600 & " hours remaining on battery."
End If
End Sub
Re: Getting a battery level
Actually I trie that first, and it doesn't return the correct info on my battery. Well, actually it doesnt' return any at all XD
Anyways, I fixed it. I created a form, then in the class module I created an instance of the form, "Dim Sys As New Form1" and later used "Batt = Sys.Sysinfo1.BatteryLevelPercent" (Or whatever the name of that specific property was).
Re: Getting a battery level
Very cool Hack. I love learning about APIs. :bigyello:
Re: Getting a battery level
Quote:
Originally Posted by nmadd
Very cool Hack. I love learning about APIs. :bigyello:
Have a look here. API Heaven :D
Re: Getting a battery level
Quote:
Originally Posted by Hack
Have a look
here. API Heaven :D
Oh yeah! Where's the drooling smiley? :bigyello:
Re: Getting a battery level
Quote:
Originally Posted by
Topkasa
Thanks. I am having some problems though...
Option Explicit
Public Function main()
Dim Sys As SysInfoLib.SysInfo
main = Sys.BatteryLifePercent <- this line creates the error below
End Function
Creates run-time error 91, "Object Variable or With Block not set." This is in a class module. I've tried adding "New" in there, but that just tells me it's an improper use of the new keyword. Is there anything you can see that I'm doing wrong?
Hey man, you have to instantiate your object before using it, so replace:
Dim Sys As SysInfoLIb.SysInfo by:
Dim Sys As new SysInfoLib.SysInfo
good luck
Re: Getting a battery level
Just put an instance of the SysInfo control on a Form like any other control. You're fighting the obvious approach.
This also gets you normal control event binding so you can detect changes without polling the value.
Re: Getting a battery level
Am I the only one noticing that this thread is 3 years old? :D
Re: Getting a battery level
michelnacouzi fooled us all :D
Actually it's me with another user account so you don't know your powerful foe.Trying to create an app so i can get the battery energy of all the laptops in the word so i can became the great X-Man Energlaptoper. :eek:
Sorry 8 hours of straight computing is getting to my brain.
Re: Getting a battery level
haha yeah I think someone needs to go to bed :D