Una funzione comoda per creare oggetti in vbscript in modo simile a javascript.
Esempio :
Insomma in una riga si crea un oggetto...codice:Set Obj = HashTable("Nome:'Lorenzo',Email:'loren@boh.it',Info:CreateObject('Scripting.Dictionary')") Response.Write Obj.Name & " " Response.Write Obj.Email & " " Obj.Info("Via") = "Mazzini" Set Obj = Nothing
Spero vi sia utile..
Ciaocodice:<% Function HashTable(List) Dim i,Dic,tName,Out,Init,Vars,Close,Elm Dim Ch,Value,Key,InString,IsValue List = Replace(List,"'",chr(34)) Set Dic = Server.CreateObject ("Scripting.Dictionary") Dic.CompareMode=1 InString = False IsValue = False Value = "" Key = "" For i=1 to len(List) Ch = Mid(List,i,1) if InString then Value = Value & Ch If ch=chr(34) then InString = False elseif ch=chr(34) then Value = Value & Ch InString=True elseif ch=":" then IsValue=True elseif ch="," then Dic(Key)=Value:Value = "":Key = "":IsValue=False else if IsValue then Value = Value & Ch:else:Key = Key & Ch:End If end if Next Dic(Key)=Value Init = "":Vars = "":Close="" for each elm in Dic.Keys Value = Dic(Elm) Vars = Vars & "Public " & elm & vbCrLf if Mid(Value,1,1)<>Chr(34) then If InStr(1,Value,"CreateObject",1)>0 or InStr(1,Value,"new ",1)>0 then Close = Close & Elm & ".close()" & VbCrLF & "Set " & Elm &"=nothing" & VbCrLF elm = "Set " & Elm end if end if Init = Init & elm & "="& Value & vbCrLf next Out = "Class cHashTable" & VbCrLf & Vars & "Private Sub Class_Initialize()" & VbCrLf & Init & "End Sub" & VbCrLf &_ "Private Sub Class_Terminate()" & VbCrLf & "On Error resume next" & VbCrLf & Close & "On Error goto 0" & VbCrLf & "End Sub" & VbCrLf & "End Class" & VbCrLf &_ "Set HashTable = new cHashTable" Execute Out Set Dic = Nothing End Function %>

Rispondi quotando