Solved

Array of a specific type

Posted on 2006-10-21
1
177 Views
Last Modified: 2010-04-23
Hello experts,

I am making an application that receives various blocks of information from a server application.  One type of information that my application will need to receive, process and display (in a list box) is the name of other users who are connected to the server.

The information is sent to my application through a socket connection and blocks of data are sent as applicable....as in if someone new connects then a new block with those details is sent.  

So I know I need to use an array of some kind in order to store this information.  At first the array will be empty because the application needs to receive a data block with a new user's details.  So lets say the application gets a new user....I will clearly need to redim the array (preserving current data) to enable me to add the new data block.  That's fine and easy - no problems.  The datablock contains the user's name and their connected name (callsign if you will).  Once I have this information my program requests more information and this is sent in a different datablock.  In total the information I need to store, for each user, is:

* Callsign
* Name
* Frequency
* Rating
* Sector File

All the above are string values.  

Now my question is how do I store that specific information in an array?  I could define a user type but how do I get that to work with the array?  I want to be able to display the data in the array on a column based list box if applicable.  I also need to be able to easily remove users from the array (by callsign) if they disconnect.

Any help on how I can best achieve the above would be much appreciated.

Regards,

Ady
0
Comment
Question by:Ady Foot
1 Comment
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
ID: 17781444
Why not work with a class (i.e. user class) and collection.

Public NotInheritable Class User
  Private m_name As String
  Private m_callsign As String
  Private m_frequency As String
  Private m_rating As String
  Private m_sectorFile As String

  Public Sub New(ByVal Name As String)
    m_name = Name
  End Sub

  Public Property Callsign() As String
    Get
      Return m_callsign
    End Get
    Set(ByVal Value As String)
      If m_callsign <> Value Then
        m_callsign = Value
      End If
    End Set
  End Property

  Public ReadOnly Property Name() As String
    Get
      Return m_name
    End Get
  End Property
End Class

Then you create a collection of users
Dim oUser As User
Dim oCol As Collection
oCol = New Collection
oUser = New User("afoot")
oCol.Add(oUser, oUser.Name)

'To Update a setting
oCol.Item("afoot").Callsign = "test"

'To Test that your value has been set correctly
Dim xCallsign As String = oCol.Item("afoot").Callsign
'To Remove
oCol.Remove("afoot")

This is definitely easier to work with. I have only provided the Constructor, the Name Property (readonly) and the Callsign Property - you could easily fill in the rest
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now