|
-
Apr 28th, 2004, 05:39 AM
#1
Thread Starter
Fanatic Member
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:
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.
-
Apr 28th, 2004, 06:05 AM
#2
Member
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
-
Apr 28th, 2004, 06:20 AM
#3
Thread Starter
Fanatic Member
I am passing this array of colours to a function that is expecting an array of colours
-
Apr 28th, 2004, 06:24 AM
#4
Re: trying to create an array of colors
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! However I refuse to use any other Americanism!
Last edited by wossname; Apr 28th, 2004 at 06:28 AM.
I don't live here any more.
-
Apr 28th, 2004, 06:25 AM
#5
I havent tested that code by the way so I could be missing something else.
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|