|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Questionwhy 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. Try:
Dim i As Integer For i = 1 To 5 Controls("Checkbox_" & CStr(i)).BackColor = Color.Black Next The ",Object" is not valid syntax. "Robinson" <b**@bbb.com> wrote in message From the ", Object" syntax, could it supposed to have been...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. 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 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. > 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. >> > 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. >>> >> > 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. >>> >> > J***@aol.com wrote:
> why does this stament generate an error if Personally, I'd prefer to create an array of Checkboxes and loop through > Checkbox_1 through 5 : exist > > Dim i As Integer > For i = 1 To 5 > Controls("Checkbox_" & CStr(i)), Object).BackColor = Color.Black > Next 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.
Show quote
Hide quote
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message Or, if he's changing every checkbox on the form, he couldnews: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. 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. 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. > > > >
enter key press
Database Connection Designer Variables how to delete a ComboBox item About deleting file on Vista 64bit Newbie: error trying to save directory path to database Working with a database PIAs for Excel 9.0 Make Code Fail How Do I Kill Non-Printable Characters? Select All CheckBoxes Key Validation |
|||||||||||||||||||||||