164Views8Replies

Author Options:

can anyone tell me how i can make a progress bar that measures my battery life? Answered

I'm tired of leaving m laptop plugged in too long, since i am usually using it, or its open, i wanted to know if anyone could tell me how i can add a progress bar to a program that shows my battery life and can tell me when its done charging. thank you in advance

Discussions

0
None
g-one

8 years ago

OK, the following script loops once in 10 seconds to check if your laptop is pluged in AND if the charging is finished. If so then it will alert you.

Set objWMI = GetObject("winmgmts://./root\WMI")

Do
  On Error Resume Next
  Set objInstances = objWMI.InstancesOf("BatteryStatus",48)
  For Each objInstance In objInstances
    With objInstance
      If .PowerOnline Then
        If Not .Charging Then
          Set objSpVoice = Wscript.CreateObject("SAPI.SpVoice")
          objSpVoice.Speak "Unplug me please!"
          Set objSpVoice = Nothing
          MsgBox "Battery 100% charged.", vbInformation, "Battery Status"
          WScript.Quit '*** Remove this line if you don't want to leave the script.
        End If
      End If
    End With
    On Error Goto 0
  Next
  Set objInstances = Nothing
  WScript.Sleep 10000
  Err.Clear
Loop

0
None
frollard

8 years ago

Windows has this functionality built in - it should show a battery icon in the system tray.  If it doesnt look in the control panel for 'power options' or the like, and enable the icon.  Linux and mac both have similar setups.

The icon should show essentially just that, an amount charged, whether its plugged in, etc.  When unplugged, the battery will drain slowly.  If you mouse over the icon it will say something like 75% power remaining (52 minutes).  etc...

Searching google I get this

download.com has stuff like this  (free)

0
None
coldpsyco91frollard

Answer 8 years ago

i already knew that it had this built in, but for some reason my computer keeps turning it off, i just wanted to know if anyone knew how to add this into a program in VB or something so i can add an alarm or something and so i can add it to one of my programs that i always have running, thanks for the links though.

0
None
frollardcoldpsyco91

Answer 8 years ago

you should be able to set low battery and critical battery alarms and actions:

alarms can be popups, audio/visual prompts, actions can include sleep and shut down, etc.

Why it turns off automatically is the question you need to ask - why replace an existing function?  duplicating it just wastes resources...

0
None
coldpsyco91frollard

Answer 8 years ago

i can set those but i want it to have an alarm when its fully charged so i don't leave it plugged in longer than it needs to be

0
None
frollardcoldpsyco91

Answer 8 years ago

It should only use as much power as it needs - if you unplug then immediately starts using battery power...law of conservation of energy at its best.

You won't waste/save power either way...

0
None
g-onefrollard

Answer 8 years ago

Figure out if this would work for you. Case yes, later I will write it to alert you.
Save as *.vbs

Set objInstances = GetObject("winmgmts://./root\WMI").InstancesOf("BatteryStatus",48)
On Error Resume Next
For Each objInstance in objInstances
    With objInstance
        WScript.Echo "Power Online: " & .PowerOnline & vbCrLf & "Charging: " & .Charging
    End With
    On Error Goto 0
Next