• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

2 Dim Array in VB.Net

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

thanks


0
AlexPonnath
Asked:
AlexPonnath
  • 3
1 Solution
 
CJ_SCommented:
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.
0
 
RonaldBiemansCommented:
A table or a class would be the way to go here. By the way what do you mean with a 2 Dim Array.
0
 
RonaldBiemansCommented:
sorry, I meant a table or a collection would be the way to go :-)
0
 
AlexPonnathAuthor Commented:
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.

0
 
RonaldBiemansCommented:
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
        Get
            Return _Item1
        End Get
        Set(ByVal Value As String)
            _Item1 = Value
        End Set
    End Property

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now