Class 设置值后,VBScript类属性为空

Class 设置值后,VBScript类属性为空,class,asp-classic,vbscript,Class,Asp Classic,Vbscript,我在VBScript中创建了一个类,并在asp classic中使用它来稳定对象: 这是我的班级: <% Class RBAC Public dateTimeValue Public userIdValue Public fileIdValue Public actionValue Public Property Get DateTime() 'Gets the propery value

我在VBScript中创建了一个类,并在asp classic中使用它来稳定对象: 这是我的班级:

    <%
Class RBAC

    Public dateTimeValue
    Public userIdValue
    Public fileIdValue
    Public actionValue

    Public Property Get DateTime()
            'Gets the propery value
            DateTime = dateTimeValue
        End Property    
    Public Property Set DateTime(value)
            'Sets the property value
            dateTimeValue = value
    End Property

    Public Property Get UserId()
            'Gets the propery value
            UserId = userIdValue
        End Property
    Public Property Set UserId(value)
            'Sets the property value
            userIdValue = value
    End Property

    Public Property Get FileId()
            'Gets the propery value
            FileId = fileIdValue
        End Property
    Public Property Set FileId(value)
            'Sets the property value
            fileIdValue = value
    End Property

    Public Property Get Action()
            'Gets the propery value
            Action = actionValue
        End Property
    Public Property Set Action(value)
            'Sets the property value
            actionValue = value
    End Property

    Public Sub Insert()
        sqlMethods = "INSERT INTO RBAC ([DateTime],[UserId],[FileId],[Action]) VALUES ("+dateTimeValue+","+userIdValue+","+fileIdValue+","+actionValue+",)"
        Conn.Execute(sqlMethods)
    End Sub

End Class
 %>

这里我实例化一个对象并设置它的属性:

    Dim RbacObject
Set RbacObject = New RBAC
Set RbacObject.DateTime = Now
Set RbacObject.UserId = Cstr(Session("cgsid"))
sqlFileId = "SELECT int_fileid FROM tbl_SecFiles where str_filename = '"&split(Request.ServerVariables("SCRIPT_NAME"),"/cgs/")(1)&"'"
Set RS = Conn.Execute(sqlFileId)
Set RbacObject.FileId = RS("int_fileid")
Set RbacObject.Action = "<"&stringMethods&"><old>"&enabled_profiles_old&"</old><new>"&enabled_profiles_old&siteid&",</new></"&stringMethods&">"

RbacObject.Insert
Dim RbacObject
Set RbacObject=New RBAC
设置RbacObject.DateTime=Now
设置RbacObject.UserId=Cstr(会话(“cgsid”))
sqlFileId=“从tbl_SecFiles中选择int_fileid,其中str_filename=”&split(Request.ServerVariables(“SCRIPT_NAME”),“/cgs/”(1)和“”
设置RS=Conn.Execute(sqlFileId)
设置RbacObject.FileId=RS(“int_FileId”)
设置rbacbject.Action=“”启用的\u profiles\u old&“”“”启用的配置文件\u旧的&siteid&“
RbacObject.Insert

问题是,只有FileId获取值,其余字段为空,即使我将它们设置为值。我做错了什么?

Set
用于为变量分配对象。所以

Set RbacObject = New RBAC
是正确的,但所有其他语句

Set RbacObject.DateTime = Now
不是。使用

RbacObject.DateTime = Now
相反

Set RbacObject.FileId = RS("int_fileid")
是一种临界情况:
fileIdValue
将包含一个字段对象,但在“非对象上下文”(如IO或计算)中使用时,将计算为其.Value

您不应该在下一步继续出错时在
下运行可疑代码

演示

copy con 10.vbs
Class C
 Public V
End Class
Set O = New C
Set O.V = "don't do this at home."
^Z

cscript 10.vbs
... 10.vbs(5, 1) Microsoft VBScript runtime error: Object required: 'O.V'
演示II(如果您不使用
设置
分配非对象,则证明“它工作”,并指出如果“仍然不工作”,则必须有其他错误被邪恶的OERN隐藏):

输出:

cscript 10.vbs
Object required
Set O.V => ''
O.V => 'don't do this at home.'
除上述内容外,还需要为不以对象为对象的属性定义setter

Public Property Let name(value)
不如

Public Property Set name(value)

我尝试使用RbacObject.DateTime=Now,但仍然是空的。我不知道为什么你还不是经典ASP标记的mod+我已经为您的问题添加了1个SQL语句以使您达到10k。您在
Insert()
中的SQL语句也错误。您必须用单引号将非数字字段括起来,并且在字符串末尾有额外的逗号。总而言之,有很多语法错误。+1的问题,因为所有伟大的答案。
Public Property Set name(value)