Home All Groups Group Topic Archive Search About
Author
3 Dec 2006 11:59 AM
Jack
why does this stament generate an error if
Checkbox_1 through 5 : exist 

Dim i As Integer
For i = 1 To 5
  Controls("Checkbox_" & CStr(i)), Object).BackColor = Color.Black
Next


The error are
Property access must assign to the property or use its value.   

and

End of statement expected.

Author
3 Dec 2006 12:46 PM
Robinson
Try:

Dim i As Integer

For i = 1 To 5
    Controls("Checkbox_" & CStr(i)).BackColor = Color.Black
Next



The ",Object" is not valid syntax.
Author
3 Dec 2006 1:56 PM
The Grim Reaper
"Robinson" <b**@bbb.com> wrote in message
news:vtydnRtVo_SIWu_YRVnyuw@giganews.com...
> Try:
>
> Dim i As Integer
>
> For i = 1 To 5
>    Controls("Checkbox_" & CStr(i)).BackColor = Color.Black
> Next
>
>
>
> The ",Object" is not valid syntax.
From the ", Object" syntax, could it supposed to have been...

CType(Control("Checkbox_" & CStr(i), Object)).BackColor = Color.Black

Or better still;

DirectCast(Control("Checkbox_" & CStr(i), Checkbox)).BackColor = Color.Black

.... ?  Alternate ways of doing it anyway...!
________________________________
Grim Reaper
Author
3 Dec 2006 3:18 PM
Jack
I had done that previously and get the following error

Run-time exception thrown : System.NullReferenceException - The
pointer for this method was null.   

It givers the following Troubleshooting tips:

Use the "new" keyword to create an object instance.                  
                                                                    5
Check to determine if the object is null before calling the method.  

Why would it give a null exception if Checkbox_1 through five are on
the form


Show quoteHide quote
On Sun, 3 Dec 2006 12:46:16 -0000, "Robinson" <b**@bbb.com> wrote:

>Try:
>
>Dim i As Integer
>
>For i = 1 To 5
>    Controls("Checkbox_" & CStr(i)).BackColor = Color.Black
>Next
>
>
>
>The ",Object" is not valid syntax.
>
Author
3 Dec 2006 4:47 PM
Robinson
It will return null if the item in question is not in the controls
collection, for example:




Dim theControl as Control = Controls ( "thenameofthecontrol" )

If theControl IsNot Nothing Then

    ' I can use the control

    theControl.BackColor = .....

Else

    ' The control with that name does not exist in the collection

End If






<J***@aol.com> wrote in message
Show quoteHide quote
news:5aq5n2tdq35n5q25nsbuc2nl08e5152rou@4ax.com...
>
> I had done that previously and get the following error
>
> Run-time exception thrown : System.NullReferenceException - The
> pointer for this method was null.
>
> It givers the following Troubleshooting tips:
>
> Use the "new" keyword to create an object instance.
>                                                                    5
> Check to determine if the object is null before calling the method.
>
> Why would it give a null exception if Checkbox_1 through five are on
> the form
>
>
> On Sun, 3 Dec 2006 12:46:16 -0000, "Robinson" <b**@bbb.com> wrote:
>
>>Try:
>>
>>Dim i As Integer
>>
>>For i = 1 To 5
>>    Controls("Checkbox_" & CStr(i)).BackColor = Color.Black
>>Next
>>
>>
>>
>>The ",Object" is not valid syntax.
>>
>
Author
3 Dec 2006 7:22 PM
Jack
It doe generate a null

Could the problem be that the control is in a panel?



Show quoteHide quote
On Sun, 3 Dec 2006 16:47:19 -0000, "Robinson" <b**@bbb.com> wrote:

>It will return null if the item in question is not in the controls
>collection, for example:
>
>
>
>
>Dim theControl as Control = Controls ( "thenameofthecontrol" )
>
>If theControl IsNot Nothing Then
>
>    ' I can use the control
>
>    theControl.BackColor = .....
>
>Else
>
>    ' The control with that name does not exist in the collection
>
>End If
>
>
>
>
>
>
><J***@aol.com> wrote in message
>news:5aq5n2tdq35n5q25nsbuc2nl08e5152rou@4ax.com...
>>
>> I had done that previously and get the following error
>>
>> Run-time exception thrown : System.NullReferenceException - The
>> pointer for this method was null.
>>
>> It givers the following Troubleshooting tips:
>>
>> Use the "new" keyword to create an object instance.
>>                                                                    5
>> Check to determine if the object is null before calling the method.
>>
>> Why would it give a null exception if Checkbox_1 through five are on
>> the form
>>
>>
>> On Sun, 3 Dec 2006 12:46:16 -0000, "Robinson" <b**@bbb.com> wrote:
>>
>>>Try:
>>>
>>>Dim i As Integer
>>>
>>>For i = 1 To 5
>>>    Controls("Checkbox_" & CStr(i)).BackColor = Color.Black
>>>Next
>>>
>>>
>>>
>>>The ",Object" is not valid syntax.
>>>
>>
>
Author
3 Dec 2006 7:28 PM
Jack
I answered my own question.  That was the problem.

Show quoteHide quote
On Sun, 3 Dec 2006 16:47:19 -0000, "Robinson" <b**@bbb.com> wrote:

>It will return null if the item in question is not in the controls
>collection, for example:
>
>
>
>
>Dim theControl as Control = Controls ( "thenameofthecontrol" )
>
>If theControl IsNot Nothing Then
>
>    ' I can use the control
>
>    theControl.BackColor = .....
>
>Else
>
>    ' The control with that name does not exist in the collection
>
>End If
>
>
>
>
>
>
><J***@aol.com> wrote in message
>news:5aq5n2tdq35n5q25nsbuc2nl08e5152rou@4ax.com...
>>
>> I had done that previously and get the following error
>>
>> Run-time exception thrown : System.NullReferenceException - The
>> pointer for this method was null.
>>
>> It givers the following Troubleshooting tips:
>>
>> Use the "new" keyword to create an object instance.
>>                                                                    5
>> Check to determine if the object is null before calling the method.
>>
>> Why would it give a null exception if Checkbox_1 through five are on
>> the form
>>
>>
>> On Sun, 3 Dec 2006 12:46:16 -0000, "Robinson" <b**@bbb.com> wrote:
>>
>>>Try:
>>>
>>>Dim i As Integer
>>>
>>>For i = 1 To 5
>>>    Controls("Checkbox_" & CStr(i)).BackColor = Color.Black
>>>Next
>>>
>>>
>>>
>>>The ",Object" is not valid syntax.
>>>
>>
>
Author
6 Dec 2006 11:38 AM
Phill W.
J***@aol.com wrote:
> why does this stament generate an error if
> Checkbox_1 through 5 : exist 
>
> Dim i As Integer
> For i = 1 To 5
>   Controls("Checkbox_" & CStr(i)), Object).BackColor = Color.Black
> Next

Personally, I'd prefer to create an array of Checkboxes and loop through
that:

Private setChecks as CheckBox() _
    = { Me.CheckBox_1 _
    , Me.CheckBox_2 _
    ... _
    , Me.CheckBox_5 _
    }

For Each eCB as CheckBox in setChecks
    eCB.BackColor = Color.Black
Next

Regards,
    Phill  W.
Author
6 Dec 2006 5:09 PM
RobinS
Show quote Hide quote
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message
news:el6a4i$4bf$2@south.jnrs.ja.net...
> J***@aol.com wrote:
>> why does this stament generate an error if Checkbox_1 through 5 : exist
>> Dim i As Integer
>> For i = 1 To 5
>>   Controls("Checkbox_" & CStr(i)), Object).BackColor = Color.Black
>> Next
>
> Personally, I'd prefer to create an array of Checkboxes and loop through
> that:
>
> Private setChecks as CheckBox() _
>    = { Me.CheckBox_1 _
>    , Me.CheckBox_2 _
>    ... _
>    , Me.CheckBox_5 _
>    }
>
> For Each eCB as CheckBox in setChecks
>    eCB.BackColor = Color.Black
> Next
>
> Regards,
>    Phill  W.

Or, if he's changing every checkbox on the form, he could
iterate through all the controls on the form and if it's
a checkbox, change the backcolor. Then he can add and remove
checkboxes willy-nilly without having to change the code.

Robin S.
Author
6 Dec 2006 10:50 PM
Kevin S Gallagher
Sorry for a late reply but could you not use DataBinds

CheckBox2.DataBindings.Add("BackColor", CheckBox1, "BackColor")
CheckBox3.DataBindings.Add("BackColor", CheckBox1, "BackColor")
CheckBox4.DataBindings.Add("BackColor", CheckBox1, "BackColor")
CheckBox5.DataBindings.Add("BackColor", CheckBox1, "BackColor")

Then later in your code

CheckBox1.BackColor = Color.Black

Which makes all five Checkboxes have the same color?

<J***@aol.com> wrote in message
Show quoteHide quote
news:2qe5n2pi82thh9uknjmp31gt9hlccaf8td@4ax.com...
> why does this stament generate an error if
> Checkbox_1 through 5 : exist
>
> Dim i As Integer
> For i = 1 To 5
>  Controls("Checkbox_" & CStr(i)), Object).BackColor = Color.Black
> Next
>
>
> The error are
> Property access must assign to the property or use its value.
>
> and
>
> End of statement expected.
>
>
>
>