2 Dim Array in VB.Net

Posted on 2004-11-14
Last Modified: 2007-09-10
Can someone please provide me some simple code samples for VB.Net on

a) How to create a 2 Dim Array with 3 fields per row
b) Search for item in Array
c) Add Item to Array
d) how could i create a summary for all items which match a certain creteria like where total of 3 value where 1 value = A

i dont use array's often and if only 1 Deim, so i am not even sure if an Array could do all this or if it would be better to go with
a Table. In any case i would like to see some samples and if someone thinks the array is wrong way to go i am willing to listen


Question by:AlexPonnath
    LVL 22

    Expert Comment

    If you want to search using criteria you'd better of using a dataset. Read about it and find which features you can or cannot use.
    LVL 25

    Expert Comment

    A table or a class would be the way to go here. By the way what do you mean with a 2 Dim Array.
    LVL 25

    Expert Comment

    sorry, I meant a table or a collection would be the way to go :-)

    Author Comment

    Thats all good but does anyone have sample of what a collection would look like which has 2 fields and how to insert, update and find data in the collection.

    LVL 25

    Accepted Solution

    Hi AlexPonnath,

    You mean something like this

            Dim mycol As New Collection

            mycol.Add(New myItem("test1", "test1"), "test1")
            mycol.Add(New myItem("test2", "test2"), "test2")
            mycol.Add(New myItem("test3", "test3"), "test3")
            mycol.Add(New myItem("test3", "test4"), "test4")

            CType(mycol.Item("test2"), myItem).Item2 = "Changed"

            MsgBox(CType(mycol.Item("test2"), myItem).Item2)

    Public Class myItem
        Private _Item1 As String
        Private _Item2 As String
        Sub New(ByVal item1 As String, ByVal Item2 As String)
            _Item1 = item1
            _Item2 = Item2
        End Sub
        Public Property Item1() As String
                Return _Item1
            End Get
            Set(ByVal Value As String)
                _Item1 = Value
            End Set
        End Property

        Public Property Item2() As String
                Return _Item2
            End Get
            Set(ByVal Value As String)
                _Item2 = Value
            End Set
        End Property
    End Class

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    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…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now