arrays in a custom class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rooo
    New Member
    • Feb 2009
    • 2

    arrays in a custom class

    Hi all.
    First of all i want to say that i'm very new to vb.net (2008) so sorry if this is a stupid question.
    I can't figure out why this does not work.

    Public arrs(32) As ARR

    Public Class ARR
    Public nr As Integer
    Public name As New String(New Char(17) {})
    End Class

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

    Dim i As Integer

    For i = 0 To 32
    If arrs(i).nr = Nothing Then
    arrs(i).nr = something
    arrs(i).name = "something"
    Exit For
    End If
    Next i
    End Sub


    Thanks for any help on this issue
  • X Enterprises
    New Member
    • Dec 2007
    • 15

    #2
    What error do you get?

    Comment

    • Rooo
      New Member
      • Feb 2009
      • 2

      #3
      Never mind...it's solved now.
      I didn't initialize each element in the array before the read/write part.

      Thanks anyway :-)


      For n As Integer = 0 To arrs.Length - 1
      arrs(n) = New ARR
      Next

      Dim i As Integer
      Dim something As Integer = 14

      For i = 0 To 32
      If arrs(i).nr = Nothing Then
      arrs(i).nr = something
      arrs(i).name = "something"
      Exit For
      End If
      Next i

      Comment

      Working...