无法在网页上打印vbscript输出,无法在文本文件中保存vbscript输出

时间:2014-06-17 13:40:37

标签: html xml vbscript

你好

我想将vbscript输出打印到网页并使用vbscript将其保存在记事本中。

这是我用vbscript的html代码。

<html>
<body>
<SCRIPT LANGUAGE="VBScript">
    Const XMLDataFile = "D:\Automation\imp\p.xml"
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False
xmlDoc.Load(XMLDataFile)
    xmlDoc.validateOnParse = True  
    If xmlDoc.Load(XMLDataFile) Then 
        Document.write("SUCCESS loading XML File")  
    Else  
        Document.write("ERROR loading XML File")  
    End If
    counter=0  
    Set root = xmlDoc.documentElement
    Set items = root.childNodes
    for each item in items
      myPNAME = xmlDoc.getElementsByTagName("PNAME").item(counter).text
      myPTYP = xmlDoc.getElementsByTagName("PTYP").item(counter).text
      myPGROUP = xmlDoc.getElementsByTagName("PGROUP").item(counter).text
      If (Left(myPNAME, 1) = "I") Then
              IsValid = True
        If (Left(myPTYP, 1) <> "I") Then
             IsValid = False
        End If
        If (Left(myPGROUP, 1) <> "I" )Then
             IsValid = False
        End If
        If IsValid = False Then
            Document.write(myPNAME & " is not valid.")
        End If
        IsValid = True
      End If
      If (Left(myPNAME, 1) = "V") Then
            IsValid = True
            If (Left(myPTYP, 1) <> "V") Then
                IsValid = False
            End If
            If (Left(myPGROUP, 1) <> "V" )Then
                IsValid = False
            End If
            If IsValid = False Then
                Document.write(myPNAME & " is not valid.")
            End If
            IsValid = True
       End If
       If (Left(myPNAME,1) = "E") Then
      If (Left(myPNAME,5)="E_MSG")Then
    IsValid=false
      End if
          IsValid = True
          If (Left(myPTYP, 1) <> "E") Then
             IsValid = False
          End If
          If (Left(myPGROUP, 1) <> "E" )Then
              IsValid = False
          End If
          If IsValid = False Then
                Document.write(myPNAME & " is not valid.")
          End If
          IsValid = True
       End If
       If (Left(myPNAME,2) = "IT") Then
          IsValid = True
            If (Left(myPTYP, 1) <> "I") Then
              IsValid = False
            End If
            If (Left(myPGROUP, 1) <> "I" )Then
               IsValid = False
            End If
            If IsValid = False Then
                 Document.write(myPNAME & " is not valid.")
            End If
            IsValid = True
        End If
        If (Left(myPNAME,2) = "VT") Then
          IsValid = True
            If (Left(myPTYP, 1) <> "V") Then
              IsValid = False
        End If
        If (Left(myPGROUP, 1) <> "V" )Then
              IsValid = False
        End If
        If IsValid = False Then
              Document.write(myPNAME & " is not valid.")
        End If
        IsValid = True
      End If
      If (Left(myPNAME,1) = "IS") Then
          IsValid = True
         If (Left(myPTYP, 1) <> "I") Then
             IsValid = False
         End If
         If (Left(myPGROUP, 1) <> "I" )Then
            IsValid = False
         End If
        If IsValid = False Then
         Document.write(myPNAME & " is not valid.")
        End If
        IsValid = True
      End If
  If (Left(myPNAME,2) = "VS") Then
      IsValid = True
         If (Left(myPTYP, 1) <> "V") Then
            IsValid = False
         End If
         If (Left(myPGROUP, 1) <> "V" )Then
            IsValid = False
         End If
         If IsValid = False Then
             Document.write(myPNAME & " is not valid.")
         End If
         IsValid = True
      End If
counter=counter+1
   next
  </SCRIPT>
 </body>
 </html>

请提供有关如何在网页上显示vbscript输出以及如何将输出保存到记事本的解决方案。

提前谢谢。

1 个答案:

答案 0 :(得分:0)

美好的一天

首先,你是在Internet Explorer中测试的吗?你应该。

其次,你应该尝试一些更简单的东西,比如打开文本文件然后打印输出。

这是示例代码,我添加了TYPE(到脚本定义),它现在输出:

<HTML>
<HEAD><TITLE>A Simple First Page</TITLE>
<SCRIPT LANGUAGE="VBScript" type="text/VBScript">
<!--

document.Write("Please don't click me")

Sub Button1_OnClick
   MsgBox "Mirabile visu."
   document.Write("<b>Hello World</b>")
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>A Simple First Page</H3><HR>
<FORM><INPUT NAME="Button1" TYPE="BUTTON" VALUE="Click Here"></FORM>
</BODY>
</HTML>

如果您要查找有关如何将输出保存到文本文件的信息,请查看VBScript指南。

http://msdn.microsoft.com/en-us/library/sx7b3k7y(v=vs.84).aspx

写入文本文件看起来像这样,但建议您尝试做什么,可能会遇到安全问题(可能需要假冒)。

Const FOR_READING = 1
Const FOR_WRITING = 2

strFileName = "C:\scripts\test.txt"
strNewContent  = "sample string content"

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strFileName,FOR_READING)
strContents = objTS.ReadAll
objTS.Close
Set objTS = objFS.OpenTextFile(strFileName,FOR_WRITING)
objTS.WriteLine strNewContent
objTS.Write strContents