home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD2001.psc / My Projects / HTTPServer / V2.0 / HTTPParameterList.cls < prev    next >
Encoding:
Visual Basic class definition  |  1999-04-29  |  3.1 KB  |  122 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "HTTPParameterList"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = False
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Collection" ,"HTTPParameter"
  16. Attribute VB_Ext_KEY = "Member0" ,"HTTPParameter"
  17. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  18. Option Explicit
  19.  
  20. 'local variable to hold collection
  21. Private mCol As Collection
  22. Public Function AddItems(Request As String, Optional NewCol As Boolean = False) As Boolean
  23.  
  24.   Dim col As Collection
  25.   Dim objNew As HTTPParameter
  26.   Dim iLoop As Long
  27.   
  28.   On Error GoTo AddItemsError
  29.   
  30.   If NewCol Then
  31.     Set mCol = New Collection
  32.   End If
  33.  
  34.   Set col = URLDecode(Request)
  35.   
  36.   For iLoop = 1 To col.Count
  37.     Set objNew = New HTTPParameter
  38.     If objNew.Initialize(col(iLoop)) = False Then
  39.       'Debug.Assert False
  40.       Exit Function
  41.     End If
  42.     mCol.Add objNew
  43.     Set objNew = Nothing
  44.   Next iLoop
  45.   
  46.   AddItems = True
  47.   
  48. AddItemsError:
  49.   Debug.Assert Err.Number = 0
  50.  
  51. End Function
  52.  
  53. Public Property Get Item(vntIndexKey As Variant) As HTTPParameter
  54. Attribute Item.VB_UserMemId = 0
  55.     'used when referencing an element in the collection
  56.     'vntIndexKey contains either the Index or Key to the collection,
  57.     'this is why it is declared as a Variant
  58.     'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
  59.   Set Item = mCol(vntIndexKey)
  60. End Property
  61.  
  62. Public Property Get Count() As Long
  63.     'used when retrieving the number of elements in the
  64.     'collection. Syntax: Debug.Print x.Count
  65.     Count = mCol.Count
  66. End Property
  67.  
  68.  
  69. Public Property Get NewEnum() As IUnknown
  70. Attribute NewEnum.VB_UserMemId = -4
  71. Attribute NewEnum.VB_MemberFlags = "40"
  72.     'this property allows you to enumerate
  73.     'this collection with the For...Each syntax
  74.     Set NewEnum = mCol.[_NewEnum]
  75. End Property
  76.  
  77.  
  78. Public Function ServerVariables(Key As String) As Variant
  79.  
  80.   Dim col As Collection
  81.   Dim RetVal As String
  82.   Dim CurVal As String
  83.   Dim iCount As Long
  84.   Dim iLoop As Long
  85.   
  86.   For iLoop = 1 To mCol.Count
  87.     If StrComp(mCol(iLoop).Name, Key, vbTextCompare) = 0 Then
  88.       CurVal = mCol(iLoop).Value
  89.       iCount = iCount + 1
  90.       Select Case iCount
  91.         Case 1
  92.           RetVal = CurVal
  93.           
  94.         Case 2
  95.           Set col = New Collection
  96.           col.Add RetVal
  97.           col.Add CurVal
  98.           
  99.         Case Else
  100.           col.Add CurVal
  101.       End Select
  102.     End If
  103.   Next iLoop
  104.   
  105.   If iCount > 1 Then
  106.     Set ServerVariables = col
  107.     Set col = Nothing
  108.   Else
  109.     ServerVariables = RetVal
  110.   End If
  111.  
  112. End Function
  113. Private Sub Class_Initialize()
  114.     'creates the collection when this class is created
  115.     Set mCol = New Collection
  116. End Sub
  117. Private Sub Class_Terminate()
  118.     'destroys collection when this class is terminated
  119.     Set mCol = Nothing
  120. End Sub
  121.  
  122.