我几周前开始通过启动这个程序来开始学习HTA和VBScript。如果这是一个愚蠢的问题,我仍然是新手,请原谅我。我一直在寻找两个小时,要么我不称职,要么我不知道如何搜索这个问题。
我需要这个脚本来检查三个文件;如果所有三个都存在,脚本将继续,如果缺少一个脚本,则会弹出一个对话框,告诉用户哪一个丢失了。我已经看过五种不同的方式,但这些方法对我来说都不起作用。以下方法是唯一一个不返回任何错误的方法,问题是它根本不做任何事情,它只是一个空白窗口。 (我只是先检查一个文件来测试这个)
<SCRIPT LANGUAGE="VBScript">
' Resize and center the window
' ==========================================================
sub DoResize
window.resizeTo 350,250
screenWidth = Document.ParentWindow.Screen.AvailWidth
screenHeight = Document.ParentWindow.Screen.AvailHeight
posLeft = (screenWidth - 350) / 2
posTop = (screenHeight - 250) / 2
window.moveTo posLeft, posTop
end Sub
DoResize()
</SCRIPT>
<TITLE>Test</TITLE>
<HTA:APPLICATION
Id="oInstall"
APPLICATIONNAME="Test"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
SELECTION="NO"
CONTEXTMENU = "NO"
BORDER="Dialogue"
BORDERStyle = "Normal"
INNERBORDER = "YES"
NOWRAP
SYSMENU = "YES"
>
<HEAD>
<STYLE type=text/css>
textarea {
overflow: hidden;
color: #ffffff;
border: none;
background-color: transparent;
}
</STYLE>
<body background="c:\mount\windows\system32\aopentools\Images\MSCBG.bmp">
</HEAD>
<textarea name="ProgSect" rows=1 cols=16 readonly></textarea><img src="c:\mount\windows\system32\aopentools\images\mscind.gif">
<SCRIPT LANGUAGE="VBScript">
Option Explicit
Sub Check
' Creating objects
' ==========================================================
Dim WshShell
Dim objFSO, outFile
Dim filesys
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set filesys = CreateObject("Scripting.FileSystemObject")
Set oFSO=CreateObject("Scripting.FileSystemObject")
' ==========================================================
If oFile=oFSO.FileExists("c:\users\jgainey\desktop\test.txt") Then
BeginImage
Else
MsgBox "An Error Has Occurred" & vbNewLine & "EC03: Test.txt" & vbExclamation & "ERROR"
Window.Close
End If
End Sub
Sub BeginImage
' Creating objects
' ==========================================================
Dim intWindowStyle
Dim bWaitOnReturn
Dim objShell
Dim WshShell
Dim objFSO, outFile
Dim filesys
Set objShell = CreateObject("Wscript.Shell")
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set filesys = CreateObject("Scripting.FileSystemObject")
set oFSO=CreateObject("Scripting.FileSystemObject")
set oFile=oFSO.OpenTextFile("c:\users\jgainey\desktop\test.txt",1)
text=oFile.ReadAll
document.all.ProgSect.value=text
End Sub
</SCRIPT>
</BODY>
</HTML>
结果是一个带有我的背景图片的窗口,我的.gif文件区域,就是这样,文本区域永远不会填充。当我删除test.txt文件时,不会弹出任何消息框,也不会有任何影响。
答案 0 :(得分:1)
您忘记设置事件,以便Sub Check在页面加载时运行,如下所示:
<body background="c:\mount\windows\system32\aopentools\Images\MSCBG.bmp" onload="Check">
修改强>
Sub Check方法的无错执行:
Sub Check
' Creating objects
' ==========================================================
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
' ==========================================================
If oFSO.FileExists("c:\users\jgainey\desktop\test.txt") Then
BeginImage
Else
MsgBox "An Error Has Occurred" & vbNewLine & "EC03: Test.txt" & vbExclamation & "ERROR"
Window.Close
End If
End Sub