0

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!

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by danielgr
1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.