...This is a carry over request from a previous thread in the OOP forum.<br><br>Our business deals with the Electric Utility industry. Our object model consists of some different objects like<br><br>Call, Consumer & Outage to name a few.<br><br>A Call is an object (although some will argue this point). Using the methods described is VB6 Business Objects from Wrox Publishing, each one of these objects also has an corresponding collection, such as Calls, Consumers and Outages.<br><br>When we want to get a list of calls that a consumer has made we do something like this:<br><br>Set colCalls = New CCalls<br>Set objConsumer = New CConsumer<br>objConsumer.ConsumerID = "123" 'Or whatever their number is.<br><br>If Not colCalls.Load(objConsumer) Then<br>MsgBox "Error Loading Consumers Calls"<br>EndIf<br><br>Then we use this to enumerate through the collection:<br><br>For Each objCall In colCalls<br>lstComment.Add objCall.CallerComment<br>Next objCall<br><br>The really cool thing about this is that you can pass different objects to the Calls collection. If we wanted to see a list of call that were made based on a specific outage we would do this:<br><br>If Not colCalls.Load(objOutage) Then<br>MsgBox "Error Loading Calls for Outage"<br>EndIf<br><br>In the Load event of the collection we use something called RTTI, Run Time Type Identification using the TypeName(object) statement in VB. This is how it knows what object got passed to it. The whole idea of this methodology was to be able to pass objects to objects. The Load method looks something like this:<br><br> Select Case UCase$(TypeName(objData))<br> Case "CCONSUMER"<br> Load = Consumers(objData)<br> Case "COUTAGE"<br> Load = Outages(objData)<br> End Select<br><br>Of course you can't use early binding here unless you had a base class that was implemented. We looked at that, but it was just another level down where you had to do the RTTI and put the intelligence in the wrong class. We axed it at that level and did it here.<br><br>Our object makes requests to a server by sending the XML over a Winsock connection. The server responds with XML and then it's parsed (properly) and placed in the collection. Since this information is collected in the Calls Collection, here's a little clip to show you how we Load the Call Collection based on the ConsumerID:<br><br> 'Build the XML request.<br> strSendBuffer = "<Action>" & vbCrLf & _<br> vbTab & "<ActionID>" & enuActionID.lLISTCONSUMERCALLS & "</ActionID>" & vbCrLf & _<br> vbTab & "<Consumer>" & vbCrLf & _<br> vbTab & vbTab & "<ConsumerID>" & objData.ConsumerID & "</ConsumerID>" & vbCrLf & _<br> vbTab & "</Consumer>" & vbCrLf & _<br> "</Action>"<br> <br> 'Create an instance of the winsock object<br> Set objWinsock = New CWinsock<br> <br> 'Send our XML request to the server.<br> objWinsock.SendData strSendBuffer<br> <br> 'Wait for a completed response.<br> strReceiveBuffer = objWinsock.ReceiveData<br> <br> 'Destroy the object.<br> Set objWinsock = Nothing<br> <br> 'Make sure something came back from the server.<br> If Len(strReceiveBuffer) > 0 Then<br> <br> 'Create XML Document for Data Retrieval.<br> Set objDOM = New DOMDocument<br> <br> 'Load data from XML file<br> If objDOM.loadXML(strReceiveBuffer) Then<br> <br> 'List create of XML nodes<br> Set objList = objDOM.selectNodes("//DateAndTime"<br> <br> 'Iterate through list of nodes and populate the Calls collection<br> For intLoop = 0 To objList.length - 1<br> <br> 'Create a call object.<br> Set objCall = New CCall<br> <br> 'Set the Call properties.<br> With objCall<br> <br> 'Some XML tags may not be present. For those that are missing an error is generated<br> 'during the read. Resume next is used here to allow the reading of the next tag.<br> On Error Resume Next<br> <br> .CallID = objDOM.getElementsByTagName("CallID".Item(intLoop).nodeTypedValue<br> .CallerComment = objDOM.getElementsByTagName("CallerComment".Item(intLoop).nodeTypedValue<br> '.ConsumerID = objDOM.getElementsByTagName("ConsumerID".Item(intLoop).nodeTypedValue<br> .DateAndTime = objDOM.getElementsByTagName("DateAndTime".Item(intLoop).nodeTypedValue<br> .OperatorCode = objDOM.getElementsByTagName("OperatorCode".Item(intLoop).nodeTypedValue<br> End With<br> <br> 'Add this call to a collection of calls. The collection was created in the class initialize.<br> On Error GoTo ErrMsg<br> s_colCalls.Add objCall ', "~" & objCall.CallID<br> Next<br><br>The way the XML was generated here is NOT the correct way to do it. It should have used the parser to append nodes to the document object model (DOM). This part will have to be redone, but you can get a feel for what the XML looks like.<br><br>As you can see the XML is pretty straight forward as is the object. This code you see above is never seen by the Application programmer. It's all encapsulated in the object.<br><br>This allows us to build a very thin client with very light network traffic. There are all sorts of other neat things you can do with this that I don't have time to go into, but use your imagination and I'm sure you'll think of many more uses for this.<br><br>For more information on XML, join the XML forum here at Tek-Tips!<br><br>Cheers, <p>Steve<br><a href=mailto:tribesaddict@swbell.net>tribesaddict@swbell.net</a><br><a href= > </a><br>