turn an array into an object

joe_pool_is

Well-known member
Joined
Jan 18, 2004
Messages
451
Location
Texas
I want to make this as generic as possible, so Ill use crayons as an example:
Code:
class Crayon
  public Number as short = 0
  public Name as string = ""
  public Manufacturer as string = ""
end class

private Color(64) as Crayon
Now, how do I declare my Color() array as an object so that I can read and set my variables? This is probably very basic, but it is so basic that I cant find any help on it anywhere. Thanks in advance!
 
i wouldnt use the Word " Color " to describe an instance of something , as Color is already a Class in .net. but to create an instance of your array ...
Code:
    Class Crayon
        Public Number As Short = 0
        Public Name As String = ""
        Public Manufacturer As String = ""
    End Class

    Private col(65) As Crayon

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        col(0) = New Crayon()
        With col(0)
            .Manufacturer = " microsoft "
            .Name = " bill gates "
        End With
    End Sub
 
Cute kiddos, Sysop.

I see your point. So basically, I have to initialize every element of the array first. I guess thats what I needed to know. Thanks a million!

~Joe
 
You dont have to initialize every element of an array unless you know exactly what the array will hold. If you dont know how many items will be in the array it is possible to REDIM the array as it grows or shrinks.
 
Back
Top