Solved

Array of a specific type

Posted on 2006-10-21
1
176 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

743 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

12 Experts available now in Live!

Get 1:1 Help Now