结合复选框和单选按钮,visual basic

时间:2010-02-22 19:01:55

标签: visual-studio-2008

我正在编写一个计算互联网费用的程序。三个套餐,A,B和C可供选择,花费9.95美元(10小时;额外2美元/小时),14.95美元(15小时;额外1美元/小时)和19.95美元(无限制)。

这是我为掩码文本框输入的代码(仅针对一种情况)。我想通过使用复选框和单选按钮来简化,但我以前从未使用过它们。任何提示或提示?

Case "A"
                If hours < 10 And nonprofit.ToUpper = "Y" Then
                    lstOutput.Items.Add("Total Cost is " & FormatCurrency(9.95 * 0.8))
                    'package A with nonprofit status, under limit
                ElseIf hours < 10 And nonprofit.ToUpper = "N" Then
                    lstOutput.Items.Add("Total Cost is " & FormatCurrency(9.95))
                    'package A without nonprofit status, under limit
                ElseIf hours > 10 And nonprofit.ToUpper = "Y" Then
                    lstOutput.Items.Add("Total Cost is " & FormatCurrency((9.95 + _
                        (hours - 10) * 2) * 0.8))
                    'package A with nonprofit status, over limit
                ElseIf hours > 10 And nonprofit.ToUpper = "N" Then
                    lstOutput.Items.Add("Total Cost is " & FormatCurrency(9.95 + _
                        (hours - 10) * 2))
                    'package A without nonprofit status, over limit
                End If

1 个答案:

答案 0 :(得分:1)

除非我不理解您的问题 - 它应该像修改代码以包含复选框一样简单,例如非营利组织,然后在您处理时:

Dim nonprofit As Boolean = NonProfit_CB.Checked

然后检查非营利组织是否为真(而不是检查Y / N):

If nonprofit = True Then 

RadioButtons与CheckBoxes基本相同。此外,如果您想将单选按钮组合在一起,那么只能选择其中一个组,将它们放在一个组框中...

相关问题