Collections in a custom class

R

Rick Palmer

The code below is a class I am creating in order to help facilitate a
generic "data layer" assembly. Anyway, as you see the RecordCriteria class
contains three hashtables, and a structure called RecordCriteriaItem. I
want to be able to use a for each loop to loop through the values in the
hash tables (as you can see, each RecordCriteriaItem consists of the related
objects in the three Hashtables). Something like this:

Dim rc as RecordCriteria
....
Dim item as RecordCriteriaItem
For Each item in rc
...
Next

I have no idea how to accomplish this....


THE CODE!!!!-------------------------------------------------------------

Public Class RecordCriteria

Dim OpCodes As Hashtable
Dim Values As Hashtable
Dim IsNumber As Hashtable

Structure RecordCriteriaItem
Dim RemoteFieldName As String
Dim OpCode As String
Dim Value As Object
Dim IsNumber As Boolean
End Structure

Sub New()
If OpCodes Is Nothing Then OpCodes = New Hashtable
If Values Is Nothing Then Values = New Hashtable
If IsNumber Is Nothing Then IsNumber = New Hashtable
End Sub

Sub Add(ByVal RemoteFieldName As String, ByVal Opcode As String, ByVal
Value As Object, ByVal isnumeric As Boolean)
OpCodes.Add(RemoteFieldName, Opcode)
Values.Add(RemoteFieldName, Value)
IsNumber.Add(RemoteFieldName, IsNumber)
End Sub

Sub Remove(ByVal RemoteFieldName As String)
OpCodes.Remove(RemoteFieldName)
Values.Remove(RemoteFieldName)
IsNumber.Remove(RemoteFieldName)
End Sub

Function GetItem(ByVal remotefieldname As String) As RecordCriteriaItem
GetItem.IsNumber = IsNumber(remotefieldname)
GetItem.OpCode = OpCodes(remotefieldname)
GetItem.RemoteFieldName = remotefieldname
GetItem.Value = Values(remotefieldname)
Return GetItem
End Function

Function GetSQLWHERECriteria(ByVal remotefieldname As String) As String
Dim Text As String = "("
Text = Text & remotefieldname
Text = Text & " "
Text = Text & OpCodes(remotefieldname)
Text = Text & " "
If IsNumber(remotefieldname) <> True Then Text = Text & "'"
Text = Text & Values(remotefieldname)
If IsNumber(remotefieldname) <> True Then Text = Text & "'"
Text = Text & ")"
End Function

Function GetFullSQLWHEREClause() As String
Dim Text As String = " WHERE "
Dim i As IDictionaryEnumerator
For Each i In Values
Text = Text & "(" & i.Key & " = "
If IsNumber(i.Key) <> True Then Text = Text & "'"
Text = Text & i.Value
If IsNumber(i.Key) <> True Then Text = Text & "') AND "
Next
Text = Mid(Text, 1, Len(Text) - 4)
Return Text
End Function

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top