|
-
Jul 24th, 2007, 01:34 AM
#1
Thread Starter
Junior Member
Getting a battery level
I'm trying to write a visual basic 6 DLL (ActiveX) that can read the battery level on my laptop and return it (specifically, I'm using it as a COM object in mIRC).
How might I get the level of my battery (Maximum charge and current charge)? I've looked through google, but I'm afraid I haven't been able to find anything helpful.
-
Jul 24th, 2007, 09:35 AM
#2
Re: Getting a battery level
-
Jul 24th, 2007, 11:06 AM
#3
Thread Starter
Junior Member
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 >_>
-
Jul 24th, 2007, 11:17 AM
#4
Re: Getting a battery level
I believe you should be able to. 
Good luck with your project.
-
Jul 24th, 2007, 11:31 AM
#5
Thread Starter
Junior Member
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?
-
Jul 25th, 2007, 07:02 AM
#6
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
-
Jul 25th, 2007, 11:09 AM
#7
Thread Starter
Junior Member
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).
-
Jul 25th, 2007, 11:57 AM
#8
Re: Getting a battery level
Very cool Hack. I love learning about APIs.
-
Jul 25th, 2007, 12:11 PM
#9
Re: Getting a battery level
 Originally Posted by nmadd
Very cool Hack. I love learning about APIs. 
Have a look here. API Heaven
-
Jul 25th, 2007, 12:22 PM
#10
Re: Getting a battery level
 Originally Posted by Hack
Have a look here. API Heaven 
Oh yeah! Where's the drooling smiley?
-
Jul 24th, 2010, 11:59 AM
#11
New Member
Re: Getting a battery level
 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
-
Jul 25th, 2010, 01:58 PM
#12
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.
-
Jul 29th, 2010, 05:18 PM
#13
Re: Getting a battery level
Am I the only one noticing that this thread is 3 years old?
-
Jul 30th, 2010, 06:13 PM
#14
Re: Getting a battery level
michelnacouzi fooled us all 
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. 
Sorry 8 hours of straight computing is getting to my brain.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jul 30th, 2010, 07:33 PM
#15
Re: Getting a battery level
haha yeah I think someone needs to go to bed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|