开发者

VBScript Runtime Error 91

I am trying to get the key, value attributes of the xml using the attached VB script code

<configuration>
  <appSettings>
    <add key="DeviceConnectionPortNumber" value="5002"/>
    <add key="VirtualWintalkConnectionPortNumber" value="5100"/>
  </appSettings>
</configuration>

Whenever I set Nothing to an object in the VB script code, i am getting the following error. I developed the vbscript using the macro feature of microsoft Word. I am going to use this vbscript code in ASP. How can I solve this issue?

Runtime Error 91: Objec开发者_如何学JAVAt Variable or With Block Variable not set.

Sub Manu_Parse()

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.Load ("c:\Web.Config.xml")

Set appSettingsNode = objXMLDoc.documentElement.FirstChild
Set parameterNodes = appSettingsNode.ChildNodes
For Each parameterNode In parameterNodes
    keyName = parameterNode.getAttribute("key")
    If keyName = "DeviceConnectionPortNumber" Then
        keyVal = parameterNode.getAttribute("value")
        parameterNode = Nothing
        Exit For
    End If
    parameterNode = Nothing
Next
parameterNodes = Nothing
sappSettingsNode = Nothing
objXMLDoc = Nothing
End Sub


It's been awhile since I've messed with VBScript, but I'm willing to be that you cannot change the enumerated value that is provided to you by the "For Each" loop. It's the same thing in .NET.

UPDATE:

Yup, I'm rusty, you need "Set" before the object you are setting to Nothing.

Try this...

Sub Manu_Parse()
    Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
    objXMLDoc.async = False
    objXMLDoc.Load ("c:\Web.Config.xml")

    Set appSettingsNode = objXMLDoc.documentElement.FirstChild
    Set parameterNodes = appSettingsNode.ChildNodes

    For Each parameterNode In parameterNodes
        keyName = parameterNode.getAttribute("key")
        If keyName = "DeviceConnectionPortNumber" Then
            keyVal = parameterNode.getAttribute("value")
            'parameterNode = Nothing
            Exit For
        End If
        'parameterNode = Nothing
    Next

    Set parameterNodes = Nothing
    Set sappSettingsNode = Nothing
    Set objXMLDoc = Nothing
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜