Store data keys and project pairs (Dictionary objects)

zhaozj2021-02-16  41

<% ######################################################################## ########################################################################################################################################################################################################################################## '# This class is written in the Dictionary object in Microsoft Visual Basic Scripting Edition #' #, using this class fully refer to its features and usage. # '# ​​Below is the meaning of the object of this object #' # http://www.microsoft.com/hina/vbscript/vbslang/vsobjdictionary.htm # '# This class is completely written by simple VBScript, so you can Any space that supports ASP uses it # '# to be convenient to use Dictionary objects. # '# ​​You can use it freely, but please keep copyright information! Thank you! # '# ​​#' # Edpers: chinaok # '# http://www.chinaok.net #' # 2002.8.3 # '#' #################################################################################################################################################################################################################################################### ######################################################################################################################################################################################################################################################################################################## #########

Class Dictionary

Public Copyright, Developer, Name, Version, Web

Private arykey () private aryitem () Private iComparemode

Private sub class_initialize () 'Please keep this information. Copyright = "2002 www.chinaok.net, all rights reserved." Web = "version =" 1.0B "Web =" http: // www. Chinaok.net "Redim Arykey (0) Arykey (0) =" "Aryitem (0) =" "iCompareMode = 0nd Sub

Public Function Add (SKEY, ITEM) InsertSort Skey, Item End Function

Public Function Exists (SKEY) IF BINSEARCH (SKEY) = 0 THEN EXISTS = false else exists = true endness function

Public function items () items = aryitemend function

Public function keys () keys = arykeyend function

Public Function Remove (SKEY) deleteSort Skeyend Function

Public function removeall () redim arykey (0) redim aryitem (0) = "" Aryitem (0) = "" end functionproperty get count () Dim len1, len2 len1 = ubound (arykey) len2 = ubound (Aryitem IF len1 <> len2 the redim preserve aryitem (len1) count = len1nd print

Property Get Item (SKEY) DIM ITOP ITOP = 0 ITOP = BINSearch (SKEY) IF ITOP <> 0 Then Item = Aryitem (ITOP) Else Add Skey, "Item =" End If End Property

Property Let Item (SKEY, NEWITEM) DIM ITOP ITOP = 0 ITOP = BINSearch (SKEY) IF ITOP <> 0 Then AryItem (ITOP) = NewItem Else Add Skey, NewItem End If End Property

Property Let Key (Skey, SNEWKEY) DIM ITOP ITOP = 0 ITOP = BINSearch (SKEY) IF ITOP <> 0 TEN ARYKEY (ITOP) = SNEWKEY ELSE Err.raise 19782, "MyDictionary", "Find Elements" & SKEY, " ", 0 end if End Property

Property Let Comparemode (Imode) if count ()> 0 Then Err.raise 19783, "MyDictionary", "Setting string Keyword comparison mode must be set", ",", 0 if (Imode <> 0 and) in Items Imode <> 1) Then Imode = 0 iCompareMode = Imodend Property

Property Get Comparemode () CompareMode = iCompareModeend Property

Private function binsearch (SKEY) 'Folding Algorithm Dim Result Result = 0 DIM IHigh, iLow, Imid Ihigh = Count () iLow = 1 Do While (iLow <= ihigh) IMID = (iLow iHigh) / 2 if strcomp (Arykey (IMID), SKEY, ICOMPAREMODE) = 0 Then Result = IMID EXIT Do End If IF STRComp (Arykey (IMID), SKEY, ICOMPAREMODE) = 1 Then Ihigh = IMID-1 Else iLow = IMID 1 End if loop binsearch = Resultens Function

Private function deleteesort (SKEY) DIM ITOP, I, ILEN ITOP = BINSearch (SKEY) if itop = 0 Then Err.raise 19782, "MyDictionary", "Did not find element" & SKEY, ", 0 else ilen = count () For i = itop 1 To Ilen Arykey (i-1) = arykey (i) Aryitem (i-1) = aryitem (i) Next Redim preserve arykey (ilen-1) Redim preserve aryitem (ilen-1) end ifnd functionprivate Function Insert (SKEY, ITEM) DIM I, J, ILEN ILEN = Count () Find Insert, Direct Find Insert Algorithm for I = 1 To Ilen IF (Strcomp (Arykey (i), SKEY, ICOMPAREMODE) <> - 1) THEN EXIT for end if Next if (i> ilen) THEN 'Directly insert Redim Preserve Arykey (i) Redim Preserve Aryitem (i) AryKey (i) = SKEY ARYITEM (i) = Item Else IF (Strcomp (AryKey (i), SKEY, ICOMPAREMODE) = 0) Then Err.raise 19781, "MyDictionary", "This button is associated with the collection", ", 0 else redim preserve arykey (Ilen 1) Redim Preserve AryItem (Ilen 1 ) For j = ilen 1 to i 1 step -1 Arykey (j) = arykey (j) = aryitem (j-1) Next AryKey (i) = SKEY ARYITEM (i) = item end if end if End function

'Class destroy private sub class_terminate () end sub

END CLASS

%>

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

New Post(0)