asp classic - VBScript class property is empty after setting a value -
i made class in vbscript , used in asp classic instatiate object: class:
<% class rbac public datetimevalue public useridvalue public fileidvalue public actionvalue public property datetime() 'gets propery value datetime = datetimevalue end property public property set datetime(value) 'sets property value datetimevalue = value end property public property userid() 'gets propery value userid = useridvalue end property public property set userid(value) 'sets property value useridvalue = value end property public property fileid() 'gets propery value fileid = fileidvalue end property public property set fileid(value) 'sets property value fileidvalue = value end property public property action() 'gets propery value action = actionvalue end property public property set action(value) 'sets property value actionvalue = value end property public sub insert() sqlmethods = "insert rbac ([datetime],[userid],[fileid],[action]) values ("+datetimevalue+","+useridvalue+","+fileidvalue+","+actionvalue+",)" conn.execute(sqlmethods) end sub end class %>
and here instantiate object , set it's properties:
dim rbacobject set rbacobject = new rbac set rbacobject.datetime = set rbacobject.userid = cstr(session("cgsid")) sqlfileid = "select int_fileid tbl_secfiles 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
the problem fileid gets value rest of fields empty, if set them value. doing wrong?
set
used assigning objects variables.
set rbacobject = new rbac
is correct, other statements like
set rbacobject.datetime =
are not. use
rbacobject.datetime =
instead.
set rbacobject.fileid = rs("int_fileid")
is borderline case: fileidvalue
contain field object, evaluate .value when used in 'non-object context' (like io or computations).
you shouldn't run dubious code with/under on error resume next
.
demo:
copy con 10.vbs class c public v end class set o = new c set o.v = "don't @ home." ^z cscript 10.vbs ... 10.vbs(5, 1) microsoft vbscript runtime error: object required: 'o.v'
demo ii (to prove 'it works' if don't use set
assignment of non-objects, , indicate there must other error hidden evil oern if 'still doesn't work'):
class c public v end class set o = new c on error resume next set o.v = "don't @ home." wscript.echo err.description on error goto 0 wscript.echo "set o.v => '" & o.v & "'" o.v = "don't @ home." wscript.echo "o.v => '" & o.v & "'"
output:
cscript 10.vbs object required set o.v => '' o.v => 'don't @ home.'
Comments
Post a Comment