Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
|
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2008, 12:07 PM
Authorized User
 
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create memory structure for receiving messages

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

Quote:
quote:
<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.
Quote:
quote:
[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,Coffee"
for example 2: "200,1,plate"

for the first time while i run the program for example i receive a message like "100,0,Coffee". 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.
 
Old March 4th, 2008, 04:24 PM
Authorized User
 
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 SortedDictionary 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.
 
Old March 5th, 2008, 04:13 PM
Authorized User
 
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i checked the Hashtable class. and i tried this code.

Code:
 Private IDHashTable As New Hashtable
 Private gArray As ArrayList

   Sub Add(ByVal Message As String)

               If IDHashTable.ContainsKey(myMSG.UniqueOrderID) = True Then
                    gArray = New ArrayList
                    gArray.Add(myMSG.UniqueOrderID.ToString() & "," & myMSG.Itemno.ToString() & "," & myMSG.Description.ToString())

                    IDHashTable.Add(myMSG.UniqueOrderID, gArray)
                    gArray = Nothing
                Else
                    gArray = New ArrayList
                    gArray.Add(myMSG.UniqueOrderID.ToString() & "," & myMSG.CurrOrderNo.ToString())
                    IDHashTable.Add(myMSG.UniqueOrderID, gArray)
                End If
    End Sub


but once i create a key, then i cannot add items to that key later.

when i try to create a new key for an item, its ok. but second time when i try to add a second item to that key then error occurs that

Quote:
quote:
"Item has already been added. Key in dictionary: "253683" Key being added: "253683""
so i cannot add all messages comming for an ID as group.

Quote:
quote:
<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>
when every i get a message, check whether that Id already exist and if exist add the new item under that id and if its not already exist need to create new ID. something like that.

Please help me. i'm not getting any idea right now. if you have any idea please let me know and if you can provide an example then that will be great help for me.

Thanks in advance.
 
Old March 6th, 2008, 04:30 PM
Authorized User
 
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm receiving message from a different program. when that program sends message to my current program, i need to save it, so that i can call those messages later. and later i need to send those saved message from my current program to another program where i need to display those messages seperately.

Quote:
quote:
For Example:
PGM-1 --> is the program that sends messages
PGM-2 --> is the program that receives messages from P1 and save it depends upon the Unique ID.
PGM-3 --> is the program that receives message from P2 and displays the message in a screen
CMP-1 and CMP-2 --> Two different computers that runs PGM-1
PGM-1 can be run in two different computers (for example: CMP-1 and CMP-2). so PGM-2 receives messages from both CMP-1 and CMP-2 at a time. depend upon the UniqueID we can determine which message belongs to which ID.


When new UniqueID is created by CMP-1 or CMP-2 then a message will be passed to PMG-2 like this "1000,S". so "S - Start" means new Id 1000 created. when i receive a message like "1000,A,0,Coffee", so "A - Add" means added new item for order 1000. when i receive a message like "1000,C", so "C- Closed" means the uniqueID 1000 is done (so no more items will added again to that ID.


if First i receive an Id from CMP-1 as "2000,S" and then received a message as "1500, S" from CMP-2, then Id 2000 should be saved first and then 1500. Id should be saved depends upon the first New ID received by PGM-2. and later if i receive a message like "1500,A,0,Coffee" then need to add that item under ID 1500.


and PGM-3 can display only 2 UniqueID items at a time. and PGM-3 need to display a Closed UniqueId items in screen for 30 seconds. that's why i created PGM-2 to save items.

for example: CMP-1 and CMP-2 send 5 uniqueID items like 400, 500, 100, 300 and 200 to PGM-2 and PGM-2 receives something like this.

Quote:
quote:
<Collection>
    <uniqueID ID="400">
        <Item id="400" itemno="1" desc="DDDD" />
        <Item id="400" itemno="2" desc="EEEE" />
        <Item id="400" itemno="3" desc="FFFF" />
        <Item id="400" type="C" />
    </UniqueID>
    <uniqueID ID="500">
        <Item id="500" itemno="1" type="A" desc="NNNN" />
        <Item id="500" itemno="2" type="A" desc="MMMM" />
        <Item id="500" type="C" />
    </UniqueID>
    <uniqueID ID="100">
        <Item id="100" itemno="1" type="A" desc="coffee" />
        <Item id="100" itemno="2" type="A" desc="tea" />
        <Item id="100" type="C" />
    </UniqueID>
    <uniqueID ID="300">
        <Item id="300" itemno="1" type="A" desc="AAAA" />
        <Item id="300" itemno="2" type="A" desc="BBBB" />
        '
        '
        '
        (Not closed)
        '
        '
        '
    </UniqueID>
    <uniqueID ID="200">
        <Item id="200" itemno="1" desc="cup" />
        <Item id="200" itemno="2" desc="plate" />
        <Item id="200" itemno="3" desc="spoon" />
        '
        '
        '
        (Not closed)
        '
        '
        '
    </UniqueID>
</Collection>
so here ID 400, 500 and 100 were closed ones. so when PGM-3 runs, we need to send messages for ID 400 and 500 first to PGM-3. and i need to send the message to PGM-3 as if i receive from PGM-1. for eg: for ID 400, i need to send messages like ("400,s"), ("400,A,1,DDDD"), ("400,A,2,EEEE"), ("400,A,3,FFFF"), ("400,C") to PGM-3. and once both 400 and 500 closed messages were displayed in PGM-3 for 30 seconds i need to send next 2 ID items to PGM-3. ID 100 is closed one, so it can be displayed for 30 seconds and remove from screen. but Id 300 and 200 need to display untill thoses Id's were closed.

so i need to save the received messages seperately under corresponding UniqueId. so that later while i need to send each message received for that ID to PGM-3, i can call that ID and send each messages received for that ID seperately like example 400 sending messages ("400,s"), ("400,A,1,DDDD"), ("400,A,2,EEEE"), ("400,A,3,FFFF"), ("400,C").

Hope you understand what i'm tring to do and that's why i'm tring to add items like this.

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Receiving MSMQ Messages obrienkev C# 0 August 25th, 2008 05:17 AM
not receiving any mail from new topics.. gbianchi Forum and Wrox.com Feedback 2 April 16th, 2007 07:34 AM
Create a tree structure in visual C++ limkimh88 C++ Programming 7 June 22nd, 2006 11:14 PM
Windows Service will not create event messages wlangel VB.NET 2002/2003 Basics 0 August 25th, 2005 11:17 AM
Receiving mail rajanikrishna Classic ASP Basics 11 November 24th, 2004 05:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.