Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. 2 dimensional array ?

2 dimensional array ?

Scheduled Pinned Locked Moved Visual Basic
data-structuresquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Oizo
    wrote on last edited by
    #1

    Hi I need to use a 2 dimensional array that stores a filed of type string in the first column and a field of type integer in the second. I tried using system.array but there is cast type problems. What can i use? mr oizo

    D 1 Reply Last reply
    0
    • M Mr Oizo

      Hi I need to use a 2 dimensional array that stores a filed of type string in the first column and a field of type integer in the second. I tried using system.array but there is cast type problems. What can i use? mr oizo

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You can't combine those two in the same array, though you can create you're own class or structure to hold these.

      Public Class MyDataItem
      Private _someString As String
      Private _someNumber As Integer

      Public Sub New(ByVal name As String, ByVal number As Integer)
          \_someString = name
          \_someNumber = number
      End Sub
      
      Public Property SomeString As String
          Get
              Return \_someString
          End Get
          Set(ByVal value As String)
              \_someString = value
          End Set
      End Property
      

      ...
      End Class

      And then you just create an array or collection of these little objects. I prefer to use a Generic List(Of T).

      Dim myList As New List(Of MyDataItem)
      myList.Add(New MyDataItem("Something", n))
      

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You can't combine those two in the same array, though you can create you're own class or structure to hold these.

        Public Class MyDataItem
        Private _someString As String
        Private _someNumber As Integer

        Public Sub New(ByVal name As String, ByVal number As Integer)
            \_someString = name
            \_someNumber = number
        End Sub
        
        Public Property SomeString As String
            Get
                Return \_someString
            End Get
            Set(ByVal value As String)
                \_someString = value
            End Set
        End Property
        

        ...
        End Class

        And then you just create an array or collection of these little objects. I prefer to use a Generic List(Of T).

        Dim myList As New List(Of MyDataItem)
        myList.Add(New MyDataItem("Something", n))
        

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        M Offline
        M Offline
        Mr Oizo
        wrote on last edited by
        #3

        Thanks for the help again.....:) Mr Oizo

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups