永发信息网

VB这段代码哪错啦?

答案:2  悬赏:60  手机版
解决时间 2021-08-12 11:41
  • 提问者网友:像風在裏
  • 2021-08-11 14:49

Private Function CPU_Temperature() As Integer
Dim WMIsvc As Object
Dim CltItems As Object, CltItem As Object
Dim Q As String
Set WMIsvc = GetObject("winmgmts:\\.\root\WMI")
Q = "SELECt * FROM MSAcpi_ThermalZoneTemperature"
Set CltItems = WMIsvc.ExecQuery(Q, , 48)
For Each CltItem In CltItems
CPU_Temperature = CltItem.CurrentTemperature
Next
CPU_Temperature = (CPU_Temperature - 2732) / 10
Set CltItem = Nothing
Set CltItems = Nothing
Set WMIsvc = Nothing
End Function

Private Sub Command1_Click()
Dim Unmber As Long
Unmber = CPU_Temperature + 32 * 1.8
Text1.Text = (CPU_Temperature & " ¡æ")
Text2.Text = (Unmber & "¨H")

End Sub

Private Sub Timer1_Timer(Index As Integer)
Dim Unmber As Long
Unmber = CPU_Temperature + 32 * 1.8
Text1.Text = (CPU_Temperature & " ¡æ")
Text2.Text = (Unmber & "¨H")
End Sub

最佳答案
  • 五星知识达人网友:独行浪子会拥风
  • 2021-08-11 15:47

根本不用那么长啊。


我这里有一个获得cpu温度的代码。我在vb6下面测试通过。给你发一下,如果好用的话,你选一下答案吧。


Private Sub Command1_Click()
 MsgBox "CPU 溫度 : " & CPU_Temperature & " °C"
End Sub


Private Function CPU_Temperature() As Integer
 Dim WMIsvc As Object
 Dim CltItems As Object, CltItem As Object
 Dim Q As String
 Set WMIsvc = GetObject("winmgmts:\\.\root\WMI")
 Q = "SELECt * FROM MSAcpi_ThermalZoneTemperature"
 Set CltItems = WMIsvc.ExecQuery(Q, , 48)
 For Each CltItem In CltItems
 CPU_Temperature = CltItem.CurrentTemperature
 Next
 CPU_Temperature = (CPU_Temperature - 2732) / 10
 Set CltItem = Nothing
 Set CltItems = Nothing
 Set WMIsvc = Nothing
End Function


全部回答
  • 1楼网友:毛毛
  • 2021-08-11 16:28
FOR 循环变量=初始值 TO 终止值 STEP 步长  语句内容NEXT 循环变量 你那个FOR的格式错了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯