我必须修改使用 VBScript 的页面。
我在函数中将局部变量设置为 Application 对象时遇到问题。下面的代码,在getObjectSchema
函数中,会产生一个错误:
Set LocalSchema = Application("ObjectSchema")
虽然下面的代码在主体中(在任何函数之外)工作得非常好:
Set Schema = Application("ObjectSchema")
有谁知道出了什么问题?从函数访问应用程序对象是否有任何限制?
这是完整的代码
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.style1 {
width: 87px;
}
</style>
</head>
<body>
<script type="text/vbscript">
Option Explicit
Dim ObjectSchema
Dim strXML
Dim strXML1
Dim sUserId
On Error Resume Next
Function GetUserID()
GetUserID = "{3450E0D8-EE30-48EE-B63F-486506AD1D97}"
End Function
Function getObjectSchema()
Dim LocalSchema
Set LocalSchema = Application("ObjectSchema")
If LocalSchema Is Nothing Then
Set LocalSchema = CreateObject("Scripting.Dictionary")
End if
If LocalSchema.Exists(sUserId) Then
strXML = LocalSchema.Item(sUserId)
Else
strXML = "<head><title>Title</title></head><head1><title1>Title1</title1></head1>"
LocalSchema.Add sUserId, strXML
Set Application("ObjectSchema") = LocalSchema
End if
getObjectSchema = strXML
End Function
sUserId = GetUserID()
strXML = ""
strXML1 = ""
strXML = getObjectSchema()
strXML1 = getObjectSchema()
strXML = getObjectSchema()
strXML1 = getObjectSchema()
Dim Schema
Set Schema = Application("ObjectSchema")
If Schema Is Nothing Then
Set Schema = CreateObject("Scripting.Dictionary")
End if
If Schema.Exists(sUserId) Then
strXML = LocalSchema.Item(sUserId)
Else
strXML = "<head><title>Title</title></head><head1><title1>Title1</title1></head1>"
Schema.Add sUserId, strXML
Set Application("ObjectSchema") = Schema
End if
strXML1 = strXML
</script>
</body>
</html>