(10分)Select Case轉Else if (十萬火急

2009-03-21 6:18 am
可以將以下既野轉成Else if 嗎..?請幫幫問..

Dim sum As Double = 0

If chkDrugs.Checked Then

sum +=12.51

End If

If chkDental.Checked Then

sum+ =9.68

End If

If chkVision.Checked Then

sum+=1.5

End If

If chkMedical.Checked Then

sum +=25.25

End If
txtTotal.Text = Cstr(sum)
End Sub


另外,想問呢題可唔可以轉做Loop嫁..?有既係點..??
仲有LOOP有冇分邊幾種,定係得一種..? THX

回答 (2)

2009-03-22 7:36 pm
✔ 最佳答案
因為你冇比題目
所以我惟有估下你呢題想做咩啦
睇番個段 program, 應該唔可以用 else if
因為用左 else if , 就變左只可以是但揀惟一一樣
但好明顯呢個 program 係可以揀多過一様

轉做 loop唔係唔可以, 但會將個 code 變得複雜化
同埋難明
呢題用 if係最清楚同適當

loop 分以下幾種
for...
while....
repeat
2009-03-21 9:46 am
I believe you have a window where you have 4 independent checkboxes. Independent meaning that you can choose one or more boxes, or even none.
In this case, the posted code is correct.

2009-03-21 01:46:12 補充:
If the code is replaced with else, or else if, it will be for the case where only any one box (or none) out of the four can be checked.
So the answer really depends on your problem.
Yes, you can use a loop if the checkbox objects and the associated amounts are assigned to arrays.


收錄日期: 2021-04-13 16:31:06
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090320000051KK01722

檢視 Wayback Machine 備份