从HTA开始/停止

时间:2016-06-20 08:54:04

标签: vbscript hta

我的方案:

我需要从外部连接的设备读取数据。我已经有一个VB脚本来从该设备读取数据一次。我需要在HTA中使用“开始”按钮从设备连续读取数据。我想用'Do..Loop'连续读取数据。

问题:

我还需要在HTA中设置一个“停止”按钮来停止在HTA中读取数据的过程。 点击HTA中的“开始”按钮后,HTA中的所有其他按钮都没有响应。观察到完成执行功能仅在按钮后,HTA中启用了其他按钮。在我的情况下,除非我单击“停止按钮”,否则执行不会在Do..loop中暂停。

希望我能清楚地解释我的问题,寻找解决方案。

1 个答案:

答案 0 :(得分:0)

由于您未在此处发布任何代码,因此是一个示例:

<html>
<head>
<title>Start and Stop music Example</title>
<SCRIPT Language="VBScript">
Sub PlayMusic(URL)
Call DisableButton1() 
Dim STRHTML
STRHTML = "<br>"
STRHTML = STRHTML & "<bgsound src="& url &" loop=""infinite"">"
MyMusic.InnerHTML = STRHTML
End Sub 
'******************************************
Sub DisableButton1()
    button1.disabled = True
    button2.disabled = False
End Sub
'******************************************
Sub DisableButton2()
    button2.disabled = True
    button1.disabled = False
End Sub
'******************************************
Sub StopMusic()
    Call DisableButton2()
    MyMusic.InnerHTML = ""
End Sub
'******************************************
</SCRIPT>
</head>
<body>
<input type="button" name="button1" value="Start the Music" onclick='PlayMusic("http://hackoo.alwaysdata.net/Matrix.mp3")'>
<input type="button" name="button2" value="Stop the Music" onclick="StopMusic()">
<span id ="MyMusic"></span>
</body>
</html>

另一个采用新设计的版本

<html>
<HTA:APPLICATION  
MAXIMIZEBUTTON="no"   
ICON="Winver.exe"  
SCROLL="No"  
SCROLLFLAT="yes"  
SINGLEINSTANCE="yes"    
CONTEXTMENU="no"  
SELECTION="no"/> 
<head>
<link rel="stylesheet" media="screen" type="text/css" title="design_encoder" href="&#0104;&#0116;&#0116;&#0112;&#0058;//&#0104;&#0097;&#0099;&#0107;&#0111;&#0111;&#0046;&#0097;&#0108;&#0119;&#0097;&#0121;&#0115;&#0100;&#0097;&#0116;&#0097;&#0046;&#0110;&#0101;&#0116;/&#0100;&#0101;&#0115;&#0105;&#0103;&#0110;&#0095;&#0101;&#0110;&#0099;&#0111;&#0100;&#0101;&#0114;&#0046;&#0099;&#0115;&#0115;"/>
<title>Start and stop the music by Hackoo 2016</title>
<SCRIPT Language="VBScript">
'*******************************************
Sub Window_OnLoad
    CenterWindow 400,220
End Sub
'*******************************************
Sub CenterWindow(x,y)
    window.resizeTo x, y
    iLeft = window.screen.availWidth/2 - x/2
    itop = window.screen.availHeight/2 - y/2
    window.moveTo ileft, itop
End Sub
'*******************************************
Sub PlayMusic(URL)
Call DisableButton1() 
Dim STRHTML
STRHTML = "<br>"
STRHTML = STRHTML & "<bgsound src="& url &" loop=""infinite"">"
MyMusic.InnerHTML = STRHTML
End Sub 
'******************************************
Sub DisableButton1()
    button1.disabled = True
    button2.disabled = False
End Sub
'******************************************
Sub DisableButton2()
    button2.disabled = True
    button1.disabled = False
End Sub
'******************************************
Sub StopMusic()
    Call DisableButton2()
    MyMusic.InnerHTML = ""
End Sub
'******************************************
</SCRIPT>
</head>
<body>
<br><br><hr>
<center><input type="button" name="button1" value="Start the Music" onclick='PlayMusic("http://hackoo.alwaysdata.net/Matrix.mp3")'>
<input type="button" name="button2" value="Stop the Music" onclick="StopMusic()">
<hr>
<span id ="MyMusic"></span>
<center>
</body>
</html>