'检查是否有未确认的报警
Do While oAlarm IsNot Nothing
If oAlarm.Acknowledged = False Then
'如果有未确认的报警,则播放报警声音
HMIRuntime.PlaySound "Alarm.wav"
Exit Do
End If
Set oAlarm = oAlarm.Next
Loop
'检查是否已经没有未确认的报警
If HMIRuntime.AlarmList.UnacknowledgedCount <= 0 Then
'如果已经没有未确认的报警,则停止报警声音
HMIRuntime.StopSound
End If[/code]
[quote][size=2][url=forum.php?mod=redirect&goto=findpost&pid=3075&ptid=1325][color=#999999]这般难离舍 发表于 2023-04-17 13:33[/color][/url][/size]
Dim oAlarm As Object
Set oAlarm = HMIRuntime.Alar ...[/quote]
在VB脚本中,通常每个语句都需要以End结尾,所以您需要在该代码段的末尾添加End语句。修改后的代码如下:Dim oAlarm As ObjectSet oAlarm = HMIRuntime.AlarmList(1)Do While oAlarm IsNot Nothing If oAlarm.Acknowledged = False Then HMIRuntime.PlaySound "Alarm.wav" Exit Do End If Set oAlarm = oAlarm.NextLoop If HMIRuntime.AlarmList.UnacknowledgedCount <= 0 Then HMIRuntime.StopSound End IfLoopEnd
[quote][size=2][url=forum.php?mod=redirect&goto=findpost&pid=3077&ptid=1325][color=#999999]这般难离舍 发表于 2023-04-17 13:46[/color][/url][/size]
是这样写吗
Dim oAlarm As Object
Set oAlarm = HMIR ...[/quote]
不是的,您需要将代码修改为以下形式来避免语法错误:Dim oAlarm As ObjectSet oAlarm = HMIRuntime.AlarmList(1)Do While oAlarm IsNot Nothing If oAlarm.Acknowledged = False Then HMIRuntime.PlaySound "Alarm.wav" Exit Do End If Set oAlarm = oAlarm.NextLoop If HMIRuntime.AlarmList.UnacknowledgedCount <= 0 Then HMIRuntime.StopSound End IfLoopEnd Do其中,Loop关键字和End Do语句应该成对出现,表示循环的开始和结束。请注意,在循环继续之前,您需要在Do While语句之后添加循环体的开头“Loop”关键字,并在代码段的末尾使用“End Do”语句,以表示循环的结束。如果您的代码有其他错误或问题,请随时向我提问。
[code]Dim oAlarm As Object ' 定义报警对象
Set oAlarm = HMIRuntime.AlarmList(1) ' 获取首条报警记录
' 循环检查报警列表中是否有未确认的报警,如果有则播放声音
Do While oAlarm IsNot Nothing
If oAlarm.Acknowledged = False Then
' 播放报警声音
HMIRuntime.PlaySound "Alarm.wav"
Exit Do
End If
Set oAlarm = oAlarm.Next ' 获取下一条报警记录
Loop
' 如果所有报警都已被确认,则停止播放报警声音
If HMIRuntime.AlarmList.UnacknowledgedCount <= 0 Then
HMIRuntime.StopSound
End If[/code]