trying to create an array of colors
I need to create an array of colours. I have this code but it gives me an error:
Quote:
An unhandled exception of type 'System.NullReferenceException' occurred in AceMosaic.exe
Additional information: Object reference not set to an instance of an object.
VB Code:
Dim colours() As Color
Dim c As Control
Dim intCount As Integer = -1
For Each c In gpbColours.Controls
If TypeOf c Is Label Then
If c.Name.Substring(0, c.Name.IndexOf("_")).ToLower = "lblcolour" And c.Text = "X" Then
intCount += 1
colours(intCount) = c.BackColor
End If
End If
Next
Can anyone tell me what I am doing wrong.
trying to create an array of colors
normally for the array we define something that already fixed
Dim arrayColor() As Brush = {Brushes.Blue, Brushes.Brown, Brushes.DarkOrange, Brushes.Gainsboro, Brushes.Gold, Brushes.Gray, Brushes.Green, Brushes.Khaki, Brushes.LightCoral, Brushes.LightPink, Brushes.Magenta, Brushes.OrangeRed}
for your case i more encourage you to use the ArrayList
Dim colours As New ArrayList
Dim c As Control
For Each c In gpbColours.Controls
If TypeOf c Is Label Then
If c.Name.Substring(0, c.Name.IndexOf("_")).ToLower = "lblcolour" And c.Text = "X" Then
colours.add(c.BackColor)
End If
End If
Next
Re: trying to create an array of colors
Quote:
Originally posted by davidrobin
I need to create an array of colours. I have this code but it gives me an error:
VB Code:
Dim colours() As Color
Dim c As Control
Dim intCount As Integer = -1
For Each c In gpbColours.Controls
If TypeOf c Is Label Then
If c.Name.Substring(0, c.Name.IndexOf("_")).ToLower = "lblcolour" And c.Text = "X" Then
intCount += 1
colours(intCount) = c.BackColor
End If
End If
Next
Can anyone tell me what I am doing wrong.
Yeah, you havent initialised the array.
Dim colours() as Color = new Color() {}
You may need to supply a number of elements too.
PS, you may want to start spelling Colour as Color from now on, it'll drive you mad otherwise :)
I use Color even when I'm not writing code! :eek: However I refuse to use any other Americanism!