Create memory structure for receiving messages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • remya1000
    New Member
    • Apr 2007
    • 115

    Create memory structure for receiving messages

    i'm using vb.net application program. i need to create a memory structure like this.

    <Collection>
    <uniqueID ID="100">
    <Item itemno="0" desc="coffee" />
    <Item itemno="1" desc="tea" />
    <Item itemno="2" desc="milk" />
    '
    '
    '
    '
    </UniqueID>
    <uniqueID ID="200">
    <Item itemno="0" desc="cup" />
    <Item itemno="1" desc="plate" />
    <Item itemno="2" desc="spoon" />
    '
    '
    '
    '
    </UniqueID>
    </Collection>
    or a memory structure like this.
    [100]-->[0,Cofee]-->[1,Tea]-->[2,Milk]
    [200]-->[0,cup]-->[1,Plate]-->[2,Spoon]
    when ever i receive a message i need to add that message to this kind of formatted memory structure. The message i receive will be in this format.
    for example 1: "100,0,Coff ee"
    for example 2: "200,1,plat e"

    for the first time while i run the program for example i receive a message like "100,0,Coff ee". then 100 is the UniqueID for that message. so i need to create a header name 100 and put the message (0,Cofee) under that header. after that if i receive a message like "200,0,cup" . then 200 is uniqueID for that message. so i need to check whether header 200 is already exist in that memory structure, if not then create a header name 200 and put the message (0,cup) under that header. after that if i receive a message like "100,1,tea" . then need to check whether header 100 already exist in that memory structure, if exist then add the message (1,tea) under the uniqueID 100.

    so if i receive an item who's UniqueID that's not exist in memory structure, then need to create a new header for that UniqueID and add the items under it. And if i receive an item who's UniqueID that's already exist in memory structure, then need to add that item under that UniqueID header.

    so when i need, for example if i call the header 100 then i can access the items i received for header 100 ([0,Cofee], [1,Tea], [2,Milk], ...) will be accessed. so using each UniqueID we can access the entire messages received for that ID.

    if you have any idea how to do this, please help me. i'm not getting any idea. if you can provide an example then it will be great help for me. please.

    thanks in advance.
  • remya1000
    New Member
    • Apr 2007
    • 115

    #2
    i check Dictionary properties and tried this codes.

    Code:
    Public Class Form1
    #Region "Structure"
        Structure Order
    
            'Data members        
            Private OrderID As Integer
            Private OrderDetail As SortedDictionary(Of String, Integer)
    
            Public Sub PlaceOrder(ByVal ID As Integer, ByVal Product As String, ByVal quantity As Integer)
                OrderID = ID
                OrderDetail.Add(Product, quantity)
            End Sub
    
            Public Sub UpdateOrder(ByVal Product As String, ByVal quantity As Integer)
                OrderDetail.Add(Product, quantity)
            End Sub
    
            Public Sub Init()
                Me.OrderDetail = New SortedDictionary(Of String, Integer)
            End Sub
    
            Public ReadOnly Property ID() As Integer
                Get
                    Return Me.OrderID
                End Get
            End Property
    
        End Structure
    #End Region
    
        Private placedOrder As Order = Nothing
        Private OrderList As List(Of Order) = Nothing
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'new instance of the order structure        
            placedOrder = New Order
            placedOrder.Init()
            'Place an order        
            Me.placedOrder.PlaceOrder(100, "Coffee", 200)
            'Save the order in a list of placed order        
            Me.OrderList = New List(Of Order)
            Me.OrderList.Add(placedOrder)
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim placedID As Integer = 100
            For Each o As Order In Me.OrderList
                'check if the id already exist in the list of orders            
                If o.ID = placedID Then 'if exist update                
                    o.UpdateOrder("tea", 10)
                Else 'create                
                    placedOrder = New Order
                    placedOrder.Init()
                    placedOrder.PlaceOrder(placedID, "Coffee", 20)
                    Me.OrderList.Add(placedOrder)
                End If
            Next o
        End Sub
    
    End Class
    but i'm using vb.net 2003 with framework 1.1. vb.net 2003 don't have SortedDictionar y at all. so i'm not able to continue right now. how can i proceed this in Vb.net 2003.

    i'm adding this feature to an existing program. That existing program is in vb.net 2003 framwork 1.1. Right now i can't move forward to next version of .net.

    if you have any idea please let me know and if you can provide and example then it will be great help for me. please.

    Thank in advance.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      I would think you could accomplish this with a DataTable object.
      You roughly have three columns
      Code:
      UnID | ItemNumber | ItemName
      So for example:
      Code:
      UnID | ItemNumber | ItemName
      -----------------------------------------------
      100   |      0           |  Cup
      200   |      0           |  Cup
      100   |      1           |  Spoon
      Could be kept in your DataTable.

      Doing myDataTable.Sel ect("UnID='100' ") would return a DataRow[] for all the entries that have 100 as the UnID column value.

      Comment

      Working...