选择Case / If Statement以合计一组选项按钮 [英] Select Case/If Statement to total a group of option buttons

查看:58
本文介绍了选择Case / If Statement以合计一组选项按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在表格上有一节有10个问题,编号为1-10,每个问题有3个选项按钮。每个选项按钮都有相同的响应(是,否,不知道),但每个答案都给出了每个问题的不同点值。


例如,问题1可能会问你喜欢糖果吗?如果你回答是,你将获得+1,不会获得-1,并且不知道会为你赢得零分。下一个问题可能会为你赢得-1为是,+ 2为否,依此类推。


我想在一个禁用的但是可见的文本框中为每个部分计算得分。 10个问题的结尾。问题是,我很确定使用if语句会使我已经很大的表单运行得非常慢。我倾向于使用一个选择案例(或开关)声明,但我在初始化它然后决定它实际上是在测试它时遇到了一些麻烦。


现在,请记住这是我最近的挫败尝试,我有一个带有嵌套if语句的select case语句,但是我收到一条错误消息,上面写着Case without Case Case。 br />

Hello to everybody,

I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don''t know), but each answer is given a different point value for each question.

For instance, question 1 might ask "Do you like candy?" and if you answer Yes you will get +1, No will earn you -1, and Don''t know will net you zero points. The next question might earn you -1 for Yes, +2 for No, and so on.

I would like to total the points for each section in a disabled, but visible textbox at the end of the 10 questions. Problem is, I''m fairly sure that using an if statement will make my already large form run very slowly. I''m leaning toward using a select case (or switch) statement, but I''m having some trouble initializing it and then deciding what it is I''m actually testing against.

Right now, and keep in mind that this is my most recent frustrated attempt, I have a select case statement with nested if statements, but I''m getting an error message that says "Case without Select Case."

展开 | 选择 | Wrap | 行号

推荐答案

在我看来,选择案例应该是b e指的是你所处的问题数量。让我们定义一个名为QNum的整数。

所以当你在第一个问题中,Qnum = 1,在第二个问题中,qnum = 2,依此类推。


然后只是:
It seems to me that the select case should be refered to the number of question you''re in. e.g. lets define an integer called QNum.
so when you''re in the first question, Qnum = 1, in the second one, qnum = 2 and so on.

then just:
展开 | 选择 | Wrap | 行号


首先,如果这是VB6,那么你很幸运。将控件变为控件数组(实际上是一些数组)将使您的生活更轻松。然后你可以使用一个循环,循环索引将依次指向你的每个(控制组)控件,重新使用相同的代码。


其次, Select Case 生成(据我所知)与 If ... ElseIf ... 相同的代码,因此对您的表现没有任何影响。

第三,您确实理解,发布的代码永远不会产生除零之外的任何总数吗?根据同一变量的测试,将Select Case视为一堆IF,你应该明白我的意思。记住,这不是一个循环。


哦......那个案例默认看起来像坏消息。你正在使用VB2005或2008,对吗?
First, if this is VB6, then you''re in luck. Making the controls into a control array (actually, a number of arrays) will make your life much easier. Then you can use a loop, and the loop index will point to each of your (groups of) controls in turn, re-using the same code).

Second, Select Case produces (as far as I know) the same code as If... ElseIf... and so should make no difference to your performance.

Thirdly, you do understand, right, that the code as posted will never produce any total other than zero? Just think of the Select Case as a bunch of IFs based on tests of the same variable, and you should see what I mean. Remember, it''s not a loop.

Uh oh... that Case Default looks like bad news. You''re using VB2005 or 2008, right?


你好,


你的Complie错误是因为所有的 IF没有结束IF(在案例中)..此外,Select的最后部分是Case Else,

不确定Case Default

检查:

Hi,


Your Complie error is because of all the "IF"''s do not have an End IF (Within Case).. Also, Last Part of the Select is "Case Else",
Not sure about "Case Default"
Check this :

展开 | 选择 | Wrap | 行号


这篇关于选择Case / If Statement以合计一组选项按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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