Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I want to make this as generic as possible, so I'll use crayons as an example:

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 can't find any help on it anywhere. Thanks in advance!

  • Leaders
Posted

i wouldn't 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 ...

   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

Posted
You don't have to initialize every element of an array unless you know exactly what the array will hold. If you don't know how many items will be in the array it is possible to REDIM the array as it grows or shrinks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...