我使用此代碼顯示VB 6.0中的電池狀態。但是顯示'語法錯誤'我該輸入什麼以及如何輸入?用於顯示電池狀態的VB代碼
Dim power As PowerStatus = SystemInformation.PowerStatus
Dim percent As Single = power.BatteryLifePercent
MsgBox ("Percent battery life remaining: " & percent * 100)
我使用此代碼顯示VB 6.0中的電池狀態。但是顯示'語法錯誤'我該輸入什麼以及如何輸入?用於顯示電池狀態的VB代碼
Dim power As PowerStatus = SystemInformation.PowerStatus
Dim percent As Single = power.BatteryLifePercent
MsgBox ("Percent battery life remaining: " & percent * 100)
如果您正在尋找VB6代碼(我猜)然後我發現代碼here: -
Private Sub Form_Load()
MsgBox "Battery status: " & getBatteryStatus(), vbInformation + vbOKOnly, "Battery Status"
End
End Sub
Public Function getBatteryStatus() As Integer
Dim obj As Object, obj2 As Object, stat As Integer
' Get Battery Status
' Return Value Meaning
'0 No battery
'1 The battery is discharging.
'2 The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging.
'3 Fully Charged
'4 Low
'5 Critical
'6 Charging
'7 Charging and High
'8 Charging and Low
'9 Charging and Critical
'10 Undefined
'11 Partially Charged
stat = 0
Set obj = GetObject("winmgmts:").InstancesOf("Win32_Battery")
For Each obj2 In obj 'loop in objects
stat = obj2.BatteryStatus
Next
getBatteryStatus = stat
End Function
在VB.NET,你可以嘗試這樣的: -
'Assembly: System.Windows.Forms.dll
'Namespace: System
'Namespace: Microsoft.VisualBasic
'Namespace: System.Windows.Forms
Dim power As PowerStatus = SystemInformation.PowerStatus
Dim percent As Single = power.BatteryLifePercent
MsgBox("Percent battery life remaining: " & percent * 100)
而不是顯示1,2。/ ....它可以直接顯示%還剩33% –
@DivyamSolanki: - 如果你能指定你想要哪種語言的代碼,那將是一件好事。 VB6或VB.Net。同樣在你原來的問題中更新! –
我想vb6和vb.net –
我99%肯定是*不* VB6代碼 – LittleBobbyTables
我認爲OP需要VB6中的相同代碼。他提供了VB.NET的代碼,他希望VB6中的代碼相同 –
@ Ruhal-你怎麼知道的? – LittleBobbyTables