2010-02-22 78 views
-1

我正在編寫一個程序來計算網絡費用。三種套餐,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

除非我不理解你的問題 - 它應該是爲修改代碼以包括一個複選框,如用於非營利性那麼簡單,那麼當你處理:

Dim nonprofit As Boolean = NonProfit_CB.Checked 

然後檢查是否非營利組織是真實的(而不是檢查Y/N):

If nonprofit = True Then 

RadioButtons與CheckBoxes基本相同。此外,如果您想將單選按鈕組合在一起,則只能選擇其中一組,然後將它們放入組框中...