Results 1 to 3 of 3

Thread: Return a 2 dimensional array

  1. #1

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    Return a 2 dimensional array

    How can a have a property return a 2 diemsional array? I have a property called phones that needs to return a 2 diemsional array. One diemsion of the array will tell what type the phone is i.e. home or cell and the other will house the actual phone number.
    Here is the code I had to return a 1 diemsional array, but I need to change it to 2.
    VB Code:
    1. Private mPhones() as String
    2. Public Property Phones() As String()
    3.         Get
    4.             Return mPhones
    5.         End Get
    6.         Set(ByVal Value As String())
    7.             mPhones = Value
    8.         End Set
    9.     End Property
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    To switch it to a 2 dimensional array you just need commas(I believe):
    VB Code:
    1. Private mPhones(,) As String
    2.     Public Property Phones() As String(,)
    3.         Get
    4.             Return mPhones
    5.         End Get
    6.         Set(ByVal Value As String(,))
    7.             mPhones = Value
    8.         End Set
    9.     End Property

    A more object oriented approach might be this:
    VB Code:
    1. Private _Phones As Phone()
    2.  
    3.     Public Property Phones() As Phone()
    4.         Get
    5.             Return _Phones
    6.         End Get
    7.         Set(ByVal Value As Phone())
    8.             _Phones = Value
    9.         End Set
    10.     End Property
    11.  
    12.     Public Class Phone
    13.  
    14.         Public Enum PhoneTypes
    15.             Home
    16.             Cell
    17.         End Enum
    18.  
    19.         Private _Number As String()
    20.  
    21.         Public Property Number(ByVal type As PhoneTypes) As String
    22.             Get
    23.                 Return _Number(type)
    24.             End Get
    25.             Set(ByVal Value As String)
    26.                 _Number(type) = Value
    27.             End Set
    28.         End Property
    29.  
    30.         Public Sub New()
    31.             'default
    32.             Dim ini As String() = {String.Empty, String.Empty}
    33.             _Number = ini
    34.         End Sub
    35.  
    36.         Public Sub New(ByVal home As String, ByVal cell As String)
    37.             Dim ini As String() = {home, cell}
    38.             _Number = ini
    39.         End Sub
    40.  
    41.     End Class

  3. #3

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    That worked, thanks. I am not sure about the Phone object though because I can't realy enumerate the phone type because it is unknown. There could be home or cell or work or message or whatever.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width