(Original) Dictionary class with scripting.dictionary is equivalent

xiaoxiao2021-03-06  112

The reason for writing this class is because of the "template class" written by the individual. Because there are many free personal homepage space (because of Ara pole, there is no money to buy space =. =) Does not provide FSO. So causes Scripting.Dictionary Can't be used, so "template class" can't run. So I wrote a thought of "Dictionary Class".

This class does not differ from the use of Scripting.Dictionary object, so it is previously written according to scripting.dictionary, and you can use this class without any modification. This type is more than scripting.dictionary, there is an insert Method: INSERT (SKEY, NKEY, NVAL, NMETHOD), this method is to insert new dictionary data into a dictionary location with SKEY KEY. NKey, NVAL is a key value of new datagical data and value .NMethod is inserted The location. If this value is 1, "B", "Black", or null value, it is inserted into dictionary data with SKEY to Key, otherwise the front.

code show as below:

'/ * ==================== Dictionary object class ========================== ==================== '/ * author: dead fish in water' / * date: July 14, 2004 evening '/ * Blog: http: //blog.lznews.cn/blog.asp?name= wow fish '/ * version: 1.00' / * usage: '/ * Dim objdic, SKEY, I, SVALUE' / * SET OBJDIC = New DictionaryClass' / * Add Method: Add (KEY value of the dictionary) Description: If the "Dictionary Key value" already exists, the add method failed '/*objdic.add "a", "Letter A"' add method '/*objdic.add "B", "letter B" '/*objdic.add "c", "letter C"' / * 'INSERT method: INSERT (KEY value of the inserted position, new dictionary Key value, new dictionary data, insertion Way: B, f Front) '/ * objdic.insert "a", "aa", "letter aa", "b"' /*objdic.insert "B", "BB", "Letter BB", " f "'/ *' EXISTS method, returning if there is a dictionary data that is" B "to KEY value '/*Response.write objdic.exists (" b ")' / * skey = objdic.keys' Get the KEYS collection, Array Collection) '/ * svalue = objdic.Items' Get Dictionary Data Collection (Array Collection)' / * Objdic.Item ("A") = "AAAAA" 'Item Properties Method: Return or Set D Data Data corresponding to Key' * For i = 0 to objdic.count-1 'count attribute Returns how many dictionary data' / * 'Item property method: Return or set the corresponding key Data' / * response.write objdic.Item (SKEY (i) ) & "
" / * next '/ * remove method: Remove (KEY value of the dictionary)' / * objdic.Remove ("a") 'Delete the KEY value D Data Data "/*Objdic.RemoveAll 'Empty Dictionary Data' /*Objdic.errcode 'Return to the operation dictionary (in debugging)' / * objdic.clearerr 'empty error code (in debugging)' / * set objdic = Nothing '/ * Description:' / * "

The key value of the dictionary ": In addition to the ADD method, you can use a string or order (1, 2 ..), please respect the author's intellectual property, keep this description! '/ * = ============================================================================================================================================================================================================= ======================= Class Dictionaryclassdim arryobj () 'Dictionary DIM MAXINDEX' MAXINDEX that uses this 2D array to store data is the largest of Arryobj DIM CURINDEX 'Dictionary pointer, used to point to Arryobj's pointer DIM C_ERRRCODE' Error code number private sub coplass_initialize curindex = 0 'From the subscript 0 start c_ERRCODE = 0' 0 indicates that there is no error MAXINDEX = 50 'default size Redim Arryobj (1, MaxIndex) 'Defines a two-dimensional array END SUB

Private sub class_terminate ERASE ARRYOBJ 'Clear Array END SUB

Public property get errcode 'Returns Error Code Errcode = C_ERRCODEEND Property

Public property get count 'Returns the total number of data, only returns the current value of Curindex-1. Count = Curindexend Property

Public Property Get Keys' Returns all keys for dictionary data, returns an array. Dim keycount, arrykey (), i keycount = curindex-1 redim arrykey (keycount) for i = 0 To keycount arrykey (i) = arryobj (0, i) Next Keys = ArryKey Erase ArryKeyend Property

Public Property Get Items' Returns all VALUES of Dictionary data, returns an array. Dim keycount, arryitem (), I keycount = curindex-1 redim arryitem (keycount) for i = 0 to keycount if isobject (Arryobj (1, i)) THEN SET Arryitem (i) = Arryobj (1, i) Else Arryitem (i) = arryobj (1, i) end if next items = arryitem ERRYITEMEND PROPERTY

Public Property Let Item (SKEY, SVAL) 'Dictionary Data IF Skympty (SKEY) THEN EXIT Property End If Dim I, ITYPE ITYPE = GetType (SKEY) If SKEY is numerical Inspection range if skey> curindex or skey <1 dam ererrcode = 2 EXITPERTY END if End if if ITYPE = 0 THEN for i = 0 to curindex-1 if Arryobj (0, i) = SKEY THEN ISOBJECT (SVAL) THEN SET Arryobj (1, i) = Sval Else Arryobj (1, i) = sval end if exit protection end if next elseif itype = 1 Then Skey = SKEY-1 if isobject (skey) = sval else Arryobj (1, SKEY) = Sval End If EXITPERTY END IF C_ERRCODE = 2 'errcode is 2 is replacing or find data End PropertyPublic Property Get Item (SKEY) IF SISEMPTY (SKEY) THEN Item = null exit protection End if Dim i, ipy itype = gettype (skey) if itype = 1 THEN 'If SKEY is numerical, check the range if skey> curindex or skey <1 Then Item = null exit protection End if Endiff IF itype = 0 THEN FO Ri = 0 to curindex-1 if Arryobj (0, i) = SKEY THEN IF ISOBJECT (Arryobj (1, I)) THEN SET ITEM = Arryobj (1, I) Else Item = Arryobj (1, i) end if exit property End if next elseif itype = 1 Then Skey = SKEY-1 IF IsObject (Arryobj (1, SKEY)) THEN SET ITEM = Arryobj (1, SKEY) ELSE ITEM = Arryobj (1, SKEY) End IF EXIT Property End if Item = Nullend Property

Public Sub Add (SKEY, SVAL) 'Add Dictionary' on Error Resume Next IF EXISTS (SKEY) OR C_ERRCODE = 9 THEN C_ERRCODE = 1 'Key value is not unique (empty key value can not add numbers) EXIT SUB END IF CURINDEX > MaxIndex1 maxIndex = maxIndex 1 'Each time you increase, you can change it to the required amount of Redim Preserve Arryobj (1, MAXINDEX) = CSTR (SKEY)' SKEY is an identification. Value, save the key to string type to save if isobject (sval) = sval 'sval is data Else Arryobj (1, curindex) = sval' sval is data end if curIndex = curindex 1END SUB

'/ * =============================================== ============================================================================================================================ Nkey = new dictionary NVAL = new dictionary '/ * SMETHOD = inserted mode {1, "b", "back"} = After SKEY, the new data is inserted, and the other is the front' / * = ============================================================================================================================================================================================================= ======================= Public Sub INSERT (SKEY, NKEY, NVAL, SMETHOD) IF NOTSTS (SKEY) THEN C_ERRCODE = 4 EXIT SUB END IF IF EXISTS (NKEY) or C_ERRCODE = 9 THEN C_ERRCODE = 4 'key value is not unique (empty key value can not add numbers) EXIT SUB End if Stype = GetType (SKEY)' Gets SKEY variable type DIM ArryRESULT (), i, Stype, Subindex, Sadd Redim ArryRESULT (1, curIndex) Defines an array to do temporary storage if Sisempty (SMETHOD) THETHOD = "b" is empty, the default "B" SMETHOD = LCase (CSTR SMETHOD)) Subindex = curIndex-1 sadd = 0 if stype = 0 THEN 'string type Compare if SMethod = "1" or SMethod = "or smethod =" BACK "TEN' inserts data into SKEY back for i = 0 To Subindex ArryResult (0, Sadd) = Arryobj (0, i) IF IsObject (Arryobj (1, I)) THEN SET ArryResult (1, SADD) =

Arryobj (1, I) Else ArryResult (1, Sadd) = Arryobj (1, i) end if if Irryobj (0, i) = SKEY THEN 'Insert Data Sadd = SADD 1 ArryResult (0, SADD) = NKEY ISOBJECT (nval) THEN SET ArryResult (1, sadd) = nval else arryresult (1, sadd) = nval end if end if sadd = 0 to subindex if Arryobj (0, i) = SKEY THEN ' Inserted data arryresult (0, sadd) = nkey if isobject (nval) THEN SET ArryResult (1, sadd) = nval else ArryResult (1, sadd) = nval end if sadd = sadd 1 end if ArryRESULT (0, SADD) = Arryobj (0, I) IF IsObject (Arryobj (1, I)) THEN SET Arryresult (1, Sadd) = Arryobj (1, I) Else ArryRESULT (1, Sadd) = Arryobj (1, i) end if sadd = sadd 1 Next End End End Elseif Stype = 1 Then SKEY = SKEY-1 'Dimension 1 is in line with daily habits (from 1st) if Smethod = "1" or SMETHOD = "b" or smethod = "back" the " Insert SKEY's back for i = 0 to skey 'Take SKEY Front Partial Data ArryRESULT (0, I) = Arryobj (0, i) IF IsObject (Arryobj (1, I)) THEN Set Arryresult (1, I) = Arryobj (1, I) Else ArryResult (1, I) = Arryobj (1, i) end if next 'inserted new data ArryResult (0, SKEY 1) = NKEY IF ISOBJECT (NVAL ) THEN SET ARRYRESULT (1, SKEY 1) = NVAL ELSE ARRYRESULT (1, SKEY 1) = nval end if 'Take SKEY back data for i = SKEY 1 To Subindex ArryRESULT (0, i 1) = arryobj (0, i) IF IsObject (Arryobj (1, I)) THEN SET ArryResult (1, i 1) = Arryobj (1, I) Else ArryRESULT (1, I 1) = Arryobj (1, i) End IF Next else for i = 0 to SKEY-1 '

Take SKEY-1 Front part of the data ArryResult (0, i) = Arryobj (0, i) IF IsObject (Arryobj (1, I)) THEN SET ArryResult (1, i) = Arryobj (1, i) Else ArryRESULT (1, I) = arryobj (1, i) end if next 'insertion of new data ArryResult (0, SKEY) = nkey if isobject (nval) THEN SET ArryResult (1, SKEY) = NVAL ELSE ArryResult (1, SKEY) = nval end IF 'Behind SKEY Data for i = SKEY To Subindex ArryRESULT (0, I 1) = Arryobj (0, I) IF IsObject (Arryobj (1, I)) THEN SET ArryResult (1, i 1) = arryobj (1, i) Else ArryResult (1, i 1) = Arryobj (1, i) end if next end if else c_errcode = 3 exit sub end if redim arryobj (1, curindex) 'Reset Data for i = 0 to Curindex Arryobj (0, I) = ArryResult (0, I) IF IsObject (ArryResult (1, I)) THEN SET Arryobj (1, I) = ArryResult (1, I) Else Arryobj (1, I) = ArryResult (1 , I) End If Next MaxIndex = CurIndex Erase ArryResult CurIndex = CurIndex 1 'Insert the data pointer plus one End SubPublic Function exists (sKey)' Analyzing a stored dictionary data If sIsEmpty (sKey) Then exists absent = False Exit Function END IF DIM I, VTYPE VTYPE = GetType (SKEY) IF VTYPE = 0 Then for i = 0 To curindex-1 if Arryobj (0, i) = SKEY THEN EXISTS = TRUE EXIT FUNCTION END IF NEXT ELSEIF VTYPE = 1 THEN IF SKEY <= Curindex and Skey> 0 THEN EXISTS = TRUE EXIT FUNCTION END if End if EXISTS = FALSEEND FUNCTION

Public Sub Remove (SKEY) 'According to SKEY Value Remove A Dictionary Data IF NOTETS (SKEY) THEN C_ERRCODE = 3 EXIT SUB End If Stype = GetType (SKEY)' Get SKEY Variable Type DIM ArryResult (), I, STYPE, Sadd Redim ArryResult (1, curIndex-2) 'Defines an array to use to make temporary stored sadd = 0 if stype = 0 Then' string type Compare for i = 0 to curIndex-1 IF Arryobj (0, i) <> SKEY THEN ArryResult (0, Sadd) = Arryobj (0, i) IF IsObject (Arryobj (1, I)) THEN SET ArryResult (1, Sadd) = Arryobj (1, I) Else ArryRESULT (1, SADD) = Arryobj ( 1, i) end if sadd = sadd 1 end if next elseif style = 1 Then SKEY = SKEY-1 'minus 1 is in line with daily habits (starting from 1) for i = 0 to curIndex-1 if i <> SKEY Then ArryResult (0, Sadd) = Arryobj (0, i) IF IsObject (Arryobj (1, I)) THEN SET ArryResult (1, Sadd) = Arryobj (1, I) Else ArryRESULT (1, SADD) = Arryobj (1 , I) end if sadd = sadd 1 end if next else c_ERRCODE = 3 exit sub end if maxIndex = curindex-2 redim arryobj (1, maxindex) 'Reset Data for i = 0 To MaxIndex Arry Obj (0, i) = ArryResult (0, i) IF IsObject (ArryResult (1, i)) THEN SET Arryobj (1, I) = ArryResult (1, i) else Arryobj (1, i) = ArryResult (1, I) end if next Erase ArryResult curindex = curindex-1 'minus one is REMOVE Data pointer End Subpublic Sub Removeall' All Clear Dictionary Data, only Redim is OK Redim Arryobj (MAXINDEX) CurIndex = 0END SUB

Public Sub Clearerr 'Reset Error C_ERRCODE = 0END SUB

Private function sisempty (sival) determining whether Sval is null value if ISempty (sval) THEN C_ERRCODE = 9 'key value empty error code SISEMPTY = true exit function end if if isnull (sval) THEN c_ERRCODE = 9' KEY value is empty error code sIsEmpty = True Exit Function End If If Trim (sVal) = "" Then C_ErrCode = 9 'Key is empty error code sIsEmpty = True Exit Function End If sIsEmpty = FalseEnd FunctionPrivate Function GetType (sVal)' acquires the variable Sval Variable Type DIM Stype Stype = Typename (Sval) Select Case Stype Case "String" gettype = 0 case "integer", "long", "single", "double" gettype = 1 Case Else gettype = -1 End SelectEnd Function

END CLASS

转载请注明原文地址:https://www.9cbs.com/read-125595.html

New Post(0)