473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

why doesn't this For Each work?

I have a working version of my survey program, but i'm trying to optimize
now. On the last page, i have a sub that examines all of the answers and
assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to append
the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next
Nov 21 '05 #1
18 1203
I don't see you declaring subctrl. What errors are you getting?

Bernie Yaeger

"Martin Williams" <ma*******@comcast.net> wrote in message
news:yv********************@comcast.com...
I have a working version of my survey program, but i'm trying to optimize
now. On the last page, i have a sub that examines all of the answers and
assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to
append
the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next

Nov 21 '05 #2
I made it a little more generic so I could run it easily and found the
errors. Here is the code as I was able to make it run:

Dim ctrl As Control
Dim ctrl2 As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is Panel Then
If ctrl.Name Is Me.Panel1.Name Then
For Each ctrl2 In ctrl.Controls
If TypeOf ctrl2 Is CheckBox Then
Dim cb As CheckBox = DirectCast(ctrl2, CheckBox)
If cb.Checked = True Then
'your code...
End If
End If
Next
End If
End If
Next

"Martin Williams" wrote:
I have a working version of my survey program, but i'm trying to optimize
now. On the last page, i have a sub that examines all of the answers and
assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to append
the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next

Nov 21 '05 #3
Also change "Is" to "=" when comparing strings.

"Martin Williams" wrote:
I have a working version of my survey program, but i'm trying to optimize
now. On the last page, i have a sub that examines all of the answers and
assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to append
the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next

Nov 21 '05 #4
You have a potential problem --- if one of the panel's values isn't a
checkbox, I think you'll have an invalid cast exception. This should work
for you though

Dim sbQ4 As New StringBuilder

For Each ctrl As Control In Me.Controls

If TypeOf ctrl Is Panel AndAlso ctrl.Name Is Me.panMain.Name Then

For Each Subctrl As Control In ctrl.Controls

If TypeOf Subctrl Is CheckBox AndAlso CType(Subctrl, CheckBox).Checked Then

sbQ4.Append(Subctrl.Text + ", ")

End If

Next

End If

Next
--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Martin Williams" <ma*******@comcast.net> wrote in message
news:yv********************@comcast.com...
I have a working version of my survey program, but i'm trying to optimize
now. On the last page, i have a sub that examines all of the answers and
assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to append the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next

Nov 21 '05 #5
Bernie - it's a little elusive as far as subctrl - in the 1.1 framework you
can declare it in the loop so this subctrl as checkbox
serves as the declaration

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
I don't see you declaring subctrl. What errors are you getting?

Bernie Yaeger

"Martin Williams" <ma*******@comcast.net> wrote in message
news:yv********************@comcast.com...
I have a working version of my survey program, but i'm trying to optimize
now. On the last page, i have a sub that examines all of the answers and assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to
append
the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next


Nov 21 '05 #6
Well, all the objects in this particular panel are checkboxes. But, this
revised code is still not working.

"W.G. Ryan eMVP" <Wi*********@NoSpam.gmail.com> wrote in message
news:ev**************@tk2msftngp13.phx.gbl...
You have a potential problem --- if one of the panel's values isn't a
checkbox, I think you'll have an invalid cast exception. This should work
for you though

Dim sbQ4 As New StringBuilder

For Each ctrl As Control In Me.Controls

If TypeOf ctrl Is Panel AndAlso ctrl.Name Is Me.panMain.Name Then

For Each Subctrl As Control In ctrl.Controls

If TypeOf Subctrl Is CheckBox AndAlso CType(Subctrl, CheckBox).Checked Then
sbQ4.Append(Subctrl.Text + ", ")

End If

Next

End If

Next
--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Martin Williams" <ma*******@comcast.net> wrote in message
news:yv********************@comcast.com...
I have a working version of my survey program, but i'm trying to optimize now. On the last page, i have a sub that examines all of the answers and assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to

append
the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next


Nov 21 '05 #7
When you say it isn't working - is it throwing an exception, is it not
giving you the desired values, what specifically is not working?

That code should work if the form is the container object of the panel.
Throw in a Debug.WriteLine(ctrl.Parent) and ensure that it's the form. If
it isn't, for instance if that panel is in a groupbox, then you'll need to
iterate through the parent's Controls collection instead.

The only reason I mentioned the possibly cast issue is that if you were to
ever add a control in it that wasn't a Checkbox - you'd break the code. I
wasn't being critical and I apologize if I came off that way.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Martin Williams" <ma*******@comcast.net> wrote in message
news:4s********************@comcast.com...
Well, all the objects in this particular panel are checkboxes. But, this
revised code is still not working.

"W.G. Ryan eMVP" <Wi*********@NoSpam.gmail.com> wrote in message
news:ev**************@tk2msftngp13.phx.gbl...
You have a potential problem --- if one of the panel's values isn't a
checkbox, I think you'll have an invalid cast exception. This should work
for you though

Dim sbQ4 As New StringBuilder

For Each ctrl As Control In Me.Controls

If TypeOf ctrl Is Panel AndAlso ctrl.Name Is Me.panMain.Name Then

For Each Subctrl As Control In ctrl.Controls

If TypeOf Subctrl Is CheckBox AndAlso CType(Subctrl, CheckBox).Checked

Then

sbQ4.Append(Subctrl.Text + ", ")

End If

Next

End If

Next
--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Martin Williams" <ma*******@comcast.net> wrote in message
news:yv********************@comcast.com...
I have a working version of my survey program, but i'm trying to

optimize now. On the last page, i have a sub that examines all of the answers and assigns them to variables for uploading to the dataset. A few questions have multiple checkboxes and i used multiple 'if then' statements to

append
the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next



Nov 21 '05 #8
Hey, I appreciate all the help I get from you guys.

What's happening now is that I get an "InvalidCast" error. One thing I did
forget is that in this panel, there is one textbox that remains hidden
unless the checkbox named "other" is checked. And I need to append the text
of that textbox if it's visible. How do I work that in?

"W.G. Ryan eMVP" <Wi*********@NoSpam.gmail.com> wrote in message
news:OQ**************@TK2MSFTNGP09.phx.gbl...
When you say it isn't working - is it throwing an exception, is it not
giving you the desired values, what specifically is not working?

That code should work if the form is the container object of the panel.
Throw in a Debug.WriteLine(ctrl.Parent) and ensure that it's the form. If
it isn't, for instance if that panel is in a groupbox, then you'll need to
iterate through the parent's Controls collection instead.

The only reason I mentioned the possibly cast issue is that if you were to
ever add a control in it that wasn't a Checkbox - you'd break the code. I
wasn't being critical and I apologize if I came off that way.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Martin Williams" <ma*******@comcast.net> wrote in message
news:4s********************@comcast.com...
Well, all the objects in this particular panel are checkboxes. But, this
revised code is still not working.

"W.G. Ryan eMVP" <Wi*********@NoSpam.gmail.com> wrote in message
news:ev**************@tk2msftngp13.phx.gbl...
You have a potential problem --- if one of the panel's values isn't a
checkbox, I think you'll have an invalid cast exception. This should work for you though

Dim sbQ4 As New StringBuilder

For Each ctrl As Control In Me.Controls

If TypeOf ctrl Is Panel AndAlso ctrl.Name Is Me.panMain.Name Then

For Each Subctrl As Control In ctrl.Controls

If TypeOf Subctrl Is CheckBox AndAlso CType(Subctrl, CheckBox).Checked

Then

sbQ4.Append(Subctrl.Text + ", ")

End If

Next

End If

Next
--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Martin Williams" <ma*******@comcast.net> wrote in message
news:yv********************@comcast.com...
> I have a working version of my survey program, but i'm trying to

optimize
> now. On the last page, i have a sub that examines all of the answers and
> assigns them to variables for uploading to the dataset. A few questions > have multiple checkboxes and i used multiple 'if then' statements to
append
> the text of the checked boxes to a variable.
>
> I decided to try and tighten the code, but it doesn't seem to work. Can > anyone tell me why?
>
> dim ctrl as control
> dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a

public > variable
>
> for each ctrl in frmpage2.controls
> if typeof ctrl is panel then
> if ctrl.name is frmpage2.pnlQ4 then
> for each subctrl as checkbox in frmpage2.pnlQ4.controls
> if subctrl.checked = true then
> sbQ4.append(subctrl.text + ", ")
> end if
> next
> end if
> end if
> next
>
>



Nov 21 '05 #9
Hi Martin,

You seem to be going through every single control on your form in order
to obtain a reference to a single panel control. Why do it that way? If
frmpage2 exposes the public field pnlQ4 you could iterate over it's
controls directly, saving yourself considerable time.

Perhaps something like this:

Dim pnl As Panel
Dim sbQuestion4 As New StringBuilder()

pnl = frmpage2.pnlQ4

For Each childControl In pnl.Controls
If TypeOf childControl Is Checkbox Then
' This next line should *not* fail.
Dim checkControl As Checkbox = DirectCast(childControl, CheckBox)
If checkControl.Checked Then
sbQuestion4.Append(checkControl.Text & ", ")
End If
End If
Next

Or have I completely missed what you're trying to do? :)

Regards,
-Adam.

Martin Williams wrote:
I have a working version of my survey program, but i'm trying to optimize
now. On the last page, i have a sub that examines all of the answers and
assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to append
the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next

Nov 21 '05 #10
No, you haven't missed it, that's exactly what I'm trying to do. But this
example, along with the others, doesn't seem to be assigning the value of
the checkbox text to the QuestionFourAnswer variable. When I update the
database, that field remains blank.

It almost definitely has something to do with the stringbuilder. This
works:

QuestionFourAnswer += checkcontrol.text + ", "

but this doesn't:

sbQ4.append(checkcontrol.text + ", ")

My stringbuilder is declared as:

dim sbQ4 as new stringbulder(QuestionFourAnswer)

Is there something wrong with the above declaration?

"Adam Goossens" <ad**********@users.sourceforge.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Martin,

You seem to be going through every single control on your form in order
to obtain a reference to a single panel control. Why do it that way? If
frmpage2 exposes the public field pnlQ4 you could iterate over it's
controls directly, saving yourself considerable time.

Perhaps something like this:

Dim pnl As Panel
Dim sbQuestion4 As New StringBuilder()

pnl = frmpage2.pnlQ4

For Each childControl In pnl.Controls
If TypeOf childControl Is Checkbox Then
' This next line should *not* fail.
Dim checkControl As Checkbox = DirectCast(childControl, CheckBox)
If checkControl.Checked Then
sbQuestion4.Append(checkControl.Text & ", ")
End If
End If
Next

Or have I completely missed what you're trying to do? :)

Regards,
-Adam.

Martin Williams wrote:
I have a working version of my survey program, but i'm trying to optimize now. On the last page, i have a sub that examines all of the answers and assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to append the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next

Nov 21 '05 #11
Martin,

Why do you not look at the code from Charlie, probably he assumed that you
would do it on the currenct form. I changed it bellow in this message (so
maybe typos) a little bit for when it is on a seperated instanced form.

\\\\
For Each ctrl as Control In frmPage2.Controls
If ctrl.Name = "pnlQ4f" Then
For Each ctrl2 as control In ctrl.Controls
if TypeOf ctrl2 Is CheckBox Then
If DirectCast(ctrl2 CheckBox).Checked = True Then
'your code...
End If
End If
Next
End If
Next
///

I hope this helps?

Cor

Cor
Nov 21 '05 #12
Cor,

First off, thanks to everyone for the help. Just because I didn't respond
to charlie's post, doesn't mean i didn't try it. I've tried all of them.
None work. I think it has something to do with the stringbuilder. It only
works when I have:

questionfouranswer += somecontrol.text + ", "

"Cor Ligthert" <no************@planet.nl> wrote in message
news:O2**************@TK2MSFTNGP11.phx.gbl...
Martin,

Why do you not look at the code from Charlie, probably he assumed that you
would do it on the currenct form. I changed it bellow in this message (so
maybe typos) a little bit for when it is on a seperated instanced form.

\\\\
For Each ctrl as Control In frmPage2.Controls
If ctrl.Name = "pnlQ4f" Then
For Each ctrl2 as control In ctrl.Controls
if TypeOf ctrl2 Is CheckBox Then
If DirectCast(ctrl2 CheckBox).Checked = True Then
'your code...
End If
End If
Next
End If
Next
///

I hope this helps?

Cor

Cor

Nov 21 '05 #13
Martin,

At least I would try
sbQ4.append(somecontrol.text & ",")
or even better
sbQ4.append(subctrl.text)
sbQ4.append(", ")

The + is ambigious, I dont know how this is used in the very overloaded
stringbuilder, maybe is it assumed as a decimal or something,

Cor

questionfouranswer += somecontrol.text + ", "

"Cor Ligthert" <no************@planet.nl> wrote in message
news:O2**************@TK2MSFTNGP11.phx.gbl...
Martin,

Why do you not look at the code from Charlie, probably he assumed that
you
would do it on the currenct form. I changed it bellow in this message (so
maybe typos) a little bit for when it is on a seperated instanced form.

\\\\
For Each ctrl as Control In frmPage2.Controls
If ctrl.Name = "pnlQ4f" Then
For Each ctrl2 as control In ctrl.Controls
if TypeOf ctrl2 Is CheckBox Then
If DirectCast(ctrl2 CheckBox).Checked = True Then
'your code...
End If
End If
Next
End If
Next
///

I hope this helps?

Cor

Cor


Nov 21 '05 #14
Sorry ,Cor, the & doesn't work either.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:em**************@TK2MSFTNGP09.phx.gbl...
Martin,

At least I would try
sbQ4.append(somecontrol.text & ",")
or even better
sbQ4.append(subctrl.text)
sbQ4.append(", ")

The + is ambigious, I dont know how this is used in the very overloaded
stringbuilder, maybe is it assumed as a decimal or something,

Cor

questionfouranswer += somecontrol.text + ", "

"Cor Ligthert" <no************@planet.nl> wrote in message
news:O2**************@TK2MSFTNGP11.phx.gbl...
Martin,

Why do you not look at the code from Charlie, probably he assumed that
you
would do it on the currenct form. I changed it bellow in this message (so maybe typos) a little bit for when it is on a seperated instanced form.

\\\\
For Each ctrl as Control In frmPage2.Controls
If ctrl.Name = "pnlQ4f" Then
For Each ctrl2 as control In ctrl.Controls
if TypeOf ctrl2 Is CheckBox Then
If DirectCast(ctrl2 CheckBox).Checked = True Then
'your code...
End If
End If
Next
End If
Next
///

I hope this helps?

Cor

Cor



Nov 21 '05 #15
Martin,

Because of the other answers, I did not look at your code anymore and saw
now that subcontrol was the control in controls.

I could be something in my code as and see than the directcast.

For Each ctrl as Control In frmPage2.Controls
If ctrl.Name = "pnlQ4f" Then
For Each ctrl2 as control In ctrl.Controls
if TypeOf ctrl2 Is CheckBox Then
If DirectCast(ctrl2,CheckBox).Checked = True Then
sbQ4.append(directcast(ctrl2, Checkbox).text)
sbQ4.append(", ")
End If
End If
Next
End If
Next
///

Because what you do Checkbox in XX.controls is impossible.

I hope this helps now.
(And when not than it is probably only a typo, this is very standard)

Cor
Nov 21 '05 #16
The way I have it right now, with some help from Adam, this works:

objPanel = frmPage2.pnlQ4
For Each objControl In objPanel.Controls
If TypeOf objControl Is CheckBox Then
objCheckbox = CType(objControl, CheckBox)
If objCheckbox.Checked Then
If objCheckbox.Text <> "other" Then
QuestionFourAnswer += objCheckbox.Text + ", "
End If
End If
ElseIf TypeOf objControl Is TextBox Then
objText = CType(objControl, TextBox)
QuestionFourAnswer += objText.Text + ", "
End If
Next

If I replace the questionfouranswer += objtext.text + ", " with the
stringbuilder method, it fails. I can't figure it out.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Martin,

Because of the other answers, I did not look at your code anymore and saw
now that subcontrol was the control in controls.

I could be something in my code as and see than the directcast.

For Each ctrl as Control In frmPage2.Controls
If ctrl.Name = "pnlQ4f" Then
For Each ctrl2 as control In ctrl.Controls
if TypeOf ctrl2 Is CheckBox Then
If DirectCast(ctrl2,CheckBox).Checked = True Then
sbQ4.append(directcast(ctrl2, Checkbox).text)
sbQ4.append(", ")
End If
End If
Next
End If
Next
///

Because what you do Checkbox in XX.controls is impossible.

I hope this helps now.
(And when not than it is probably only a typo, this is very standard)

Cor

Nov 21 '05 #17
Martin,

It appears as though you want the string builder to modify your
QuestionFourAnswer variable directly - this won't happen. Strings in
..NET are immutable, so when you pass in a string to the StringBuilder's
constructor a copy of this string is made. It is this copy that is
mutable - the original is still an immutable string. Any changes you
make to the StringBuilder affect only the internal mutable copy, not the
string you passed to the Constructor.

In your case the modifications you make are local to the StringBuilder
and will not affect the value of QuestionFourAnswer.

The solution is to copy the value of the StringBuilder back into
QuestionFourAnswer once you have finished building the answer:

QuestionFourAnswer = sbQ4.ToString()

Hope that helps!

Regards,
-Adam.

Martin Williams wrote:
No, you haven't missed it, that's exactly what I'm trying to do. But this
example, along with the others, doesn't seem to be assigning the value of
the checkbox text to the QuestionFourAnswer variable. When I update the
database, that field remains blank.

It almost definitely has something to do with the stringbuilder. This
works:

QuestionFourAnswer += checkcontrol.text + ", "

but this doesn't:

sbQ4.append(checkcontrol.text + ", ")

My stringbuilder is declared as:

dim sbQ4 as new stringbulder(QuestionFourAnswer)

Is there something wrong with the above declaration?

Nov 21 '05 #18
Well, I would like to thank everyone for their help. I got everything
working for this program, resulting in a significant speed boost.

"Martin Williams" <ma*******@comcast.net> wrote in message
news:yv********************@comcast.com...
I have a working version of my survey program, but i'm trying to optimize
now. On the last page, i have a sub that examines all of the answers and
assigns them to variables for uploading to the dataset. A few questions
have multiple checkboxes and i used multiple 'if then' statements to append the text of the checked boxes to a variable.

I decided to try and tighten the code, but it doesn't seem to work. Can
anyone tell me why?

dim ctrl as control
dim sbQ4 as new StringBuilder(QuestionFourAnswer) // This is a public
variable

for each ctrl in frmpage2.controls
if typeof ctrl is panel then
if ctrl.name is frmpage2.pnlQ4 then
for each subctrl as checkbox in frmpage2.pnlQ4.controls
if subctrl.checked = true then
sbQ4.append(subctrl.text + ", ")
end if
next
end if
end if
next

Nov 21 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
39
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor...
3
by: Matt | last post by:
I want to know if readOnly attribute doesn't work for drop down list? If I try disabled attribute, it works fine for drop down list. When I try text box, it works fine for both disabled and...
149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
4
by: bbp | last post by:
Hello, In an ASPX page I have a "Quit" button which make a simple redirect in code-behind. This button doesn't work no more since (I think) I moved from the framework 1.0 to 1.1 and it doesn't...
3
by: Dave Moore | last post by:
Hi All, Ok, here's my problem. I want to open a file and process its contents. However, because it is possible that the file may not exist, I also want to check whether the file() function is...
10
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
6
by: Johnny Jörgensen | last post by:
I've got a usercontrol derived from a normal ComboBox that contains some special formatting code. On my main form I've got a lot of my custom comboboxes. I discovered a bug in the derived...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.