I'm trying to figure out how to use a class.

I have created a class:

Public Class bicluster
    Public Property Vec As String
    Public Property left As String
    Public Property right As String
    Public Property distance As Double
    Public Property id As String

    Public Sub New(ByVal Vec As String, Optional ByVal Left As String = "None", Optional ByVal Right As String = "None", Optional ByVal Distance As Double = 0, Optional ByVal Id As String = "None")

        _left = Left
        _right = Right
        _vec = Vec
        _id = Id
        _distance = Distance

    End Sub
End Class

I now need to create an array of the class and assign data to it:

Private Sub hcluster(ByVal tmpRows As String, Optional ByVal Distance As String = "pearson")

        Dim rows() As String = tmpRows.Split(",")

        Dim clust() As bicluster

        For mloop As Integer = 0 To rows.Count - 1
            clust(mloop) = New bicluster(mloop, , , , "1")
        Next

End Sub



Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        hcluster("1,2,3")
End Sub

What am I doing wrong here, I get an error: Object reference not set to an instance of an object.

Thanks in advance!

You aren't specifying a size for the array. If you know how big it is going to be include the size in the initializing code

Dim clust(5) As bicluster

Or use the redim method to redefine it with a size:

ReDim clust(5)

If you don't know the size of the array use an arrayList instead as they can grow without the performance hit brought on by repeated ReDims.

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.