为什么不为每个工作? [英] why doesn't this For Each work?

查看:58
本文介绍了为什么不为每个工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的调查程序有一个工作版本,但我现在正在尝试优化

。在最后一页,我有一个子检查所有的答案和

将它们分配给变量以上传到数据集。几个问题

有多个复选框,我使用多个''if then''语句将复选框的文本附加到变量上。


我决定尝试收紧代码,但似乎没有用。可以

有人告诉我为什么吗?


dim ctrl as control

dim sbQ4 as new StringBuilder(QuestionFourAnswer)//这是一个公共

变量

每个ctrl在frmpage2.controls中的


如果typeof ctrl是面板那么

如果ctrl.name是frmpage2.pnlQ4那么
每个子菜单的
作为frmpage2.pnlQ4.controls中的复选框

如果subctrl.checked = true则

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

结束如果

next

结束如果

结束如果

next

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

推荐答案

我没有看到你声明子菜单。你得到了什么错误?


Bernie Yaeger


" Martin Williams" <毫安******* @ comcast.net>在留言中写道

新闻:yv ******************** @ comcast.com ...
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...
我有我的调查程序的工作版本,但我现在正在努力优化
。在最后一页,我有一个子检查所有答案,并将它们分配给变量以上传到数据集。一些问题
有多个复选框,我使用了多个''if then''语句来将选中框的文本附加到变量上。

我决定尝试收紧代码,但似乎没有效果。可以
任何人告诉我为什么?

dim ctrl作为控件
dim sbQ4作为新的StringBuilder(QuestionFourAnswer)//这是一个公共
变量

frmpage2.controls中的每个ctrl
如果typeof ctrl是面板那么
如果ctrl.name是frmpage2.pnlQ4然后
为每个子菜单作为frmpage2.pnlQ4.controls中的复选框
如果subctrl.checked = true那么
sbQ4.append(subctrl.text +",")
结束如果
下一个
结束如果
结束如果
下一页
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



我把它变得更通用了所以我可以轻松运行它并找到了

错误。这是我能够让它运行的代码:


Dim ctrl As Control

Dim ctrl2 As Control

For每个ctrl In Me.Controls

如果TypeOf ctrl是Panel那么

如果ctrl.Name是Me.Panel1.Name那么

For each ctrl2在ctrl.Controls

如果TypeOf ctrl2是CheckBox然后

Dim cb As CheckBox = DirectCast(ctrl2,CheckBox)

如果cb.Checked =真然后

''你的代码......

结束如果

结束如果

下一页

结束如果

结束如果

下一页


" Martin Williams"写道:
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:
我有一个调查程序的工作版本,但我现在正在努力优化
。在最后一页,我有一个子检查所有答案,并将它们分配给变量以上传到数据集。一些问题
有多个复选框,我使用多个''if then''语句将复选框的文本追加到变量。

我决定尝试收紧代码,但似乎没有用。可以
任何人告诉我为什么?

dim ctrl作为控件
dim sbQ4作为新的StringBuilder(QuestionFourAnswer)//这是一个公共
变量

frmpage2.controls中的每个ctrl
如果typeof ctrl是面板那么
如果ctrl.name是frmpage2.pnlQ4然后
为每个子菜单作为frmpage2.pnlQ4.controls中的复选框
如果subctrl.checked = true那么
sbQ4.append(subctrl.text +",")
结束如果
下一个
结束如果
结束如果
下一页
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



同时更改Is到=在比较字符串时。


" Martin Williams"写道:
Also change "Is" to "=" when comparing strings.

"Martin Williams" wrote:
我有一个调查程序的工作版本,但我现在正在努力优化
。在最后一页,我有一个子检查所有答案,并将它们分配给变量以上传到数据集。一些问题
有多个复选框,我使用多个''if then''语句将复选框的文本追加到变量。

我决定尝试收紧代码,但似乎没有用。可以
任何人告诉我为什么?

dim ctrl作为控件
dim sbQ4作为新的StringBuilder(QuestionFourAnswer)//这是一个公共
变量

frmpage2.controls中的每个ctrl
如果typeof ctrl是面板那么
如果ctrl.name是frmpage2.pnlQ4然后
为每个子菜单作为frmpage2.pnlQ4.controls中的复选框
如果subctrl.checked = true那么
sbQ4.append(subctrl.text +",")
结束如果
下一个
结束如果
结束如果
下一页
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



这篇关于为什么不为每个工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆