Results 1 to 5 of 5

Thread: trying to create an array of colors

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    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:
    1. Dim colours() As Color
    2.         Dim c As Control
    3.         Dim intCount As Integer = -1
    4.         For Each c In gpbColours.Controls
    5.             If TypeOf c Is Label Then
    6.                 If c.Name.Substring(0, c.Name.IndexOf("_")).ToLower = "lblcolour" And c.Text = "X" Then
    7.                     intCount += 1
    8.                     colours(intCount) = c.BackColor
    9.                 End If
    10.             End If
    11.         Next

    Can anyone tell me what I am doing wrong.


    Things I do when I am bored: DotNetable

  2. #2
    Member
    Join Date
    Jul 2003
    Posts
    41

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    I am passing this array of colours to a function that is expecting an array of colours
    VB Code:
    1. byval clrs() as color


    Things I do when I am bored: DotNetable

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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:
    1. Dim colours() As Color
    2.         Dim c As Control
    3.         Dim intCount As Integer = -1
    4.         For Each c In gpbColours.Controls
    5.             If TypeOf c Is Label Then
    6.                 If c.Name.Substring(0, c.Name.IndexOf("_")).ToLower = "lblcolour" And c.Text = "X" Then
    7.                     intCount += 1
    8.                     colours(intCount) = c.BackColor
    9.                 End If
    10.             End If
    11.         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.

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    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
  •  



Click Here to Expand Forum to Full Width