We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,731 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Using a class

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
27 Minutes
Discussion Span
9 Months Ago
Last Updated
3
Views
Question
Answered
danielgr
Light Poster
37 posts since Jun 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

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.

hericles
Veteran Poster
1,065 posts since Nov 2007
Reputation Points: 156
Solved Threads: 228
Skill Endorsements: 9

Thank you!

danielgr
Light Poster
37 posts since Jun 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 9 Months Ago by hericles

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0615 seconds using 2.71MB