作者suiming (台灣fighting!)
看板Visual_Basic
標題[VB6 ] 計算機程式問題
時間Sat Jul 19 21:05:14 2014
松崗的書的例子f10_7_2
1.請問42行為什麼If後不用加end if
2.每一段的select case是啥意思?opt不是要先指定嗎?為什麼opt都放最後?
Name Caption
txtBoard -
cmdNum(0) 0
cmdNum(1) 1
cmdNum(2) 2
cmdNum(3) 3
cmdNum(4) 4
cmdNum(5) 5
cmdNum(6) 6
cmdNum(7) 7
cmdNum(8) 8
cmdNum(9) 9
cmdDot .
cmdAdd +
cmdSub -
cmdCancel C
cmdAns =
cmdEnd Off
程式碼
1 Dim opt As Integer
2 Dim total As Double, temp_val As Double
3 Dim dot As Single, zero As Single
4 Const Nul = 0, Add = 1, Subb = 2, Ans = 3
5 Private Sub cmdAdd_Click()
6 Select Case opt
7 Case Nul: total = temp_val
8 Case Add: total = total + temp_val
9 Case Subb: total = total - temp_val
10 Case Ans: total = temp_val
11 End Select
12 txtBoard = Str(total)
13 temp_val = 0
14 opt = Add
15 End Sub
16 Private Sub cmdAns_Click()
17 Select Case opt
18 Case Nul: total = temp_val
19 Case Add: total = total + temp_val
20 Case Subb: total = total - temp_val
21 Case Ans: total = temp_val
22 End Select
23 txtBoard = Str(total)
24 temp_val = 0
25 opt = Ans
26 End Sub
27 Private Sub cmdCancel_Click()
28 opt = Nul
29 total = 0
30 temp_val = 0
31 txtBoard.Text = Str(temp_val)
32 End Sub
33 Private Sub cmdDot_Click()
34 dot = True
35 End Sub
36 Private Sub cmdEnd_Click()
37 End
38 End Sub
39 Private Sub cmdNum_Click(index As Integer)
40 If dot = True Then
41 temp_val = Val(Str(temp_val) + "." + Str(index))
42 If index = 0 Then zero = True
43 dot = False
44 Else
45 If zero = True Then
46 temp_val = Val(Str(temp_val) + ".0" + Str(index))
47 zero = False
48 Else
49 temp_val = Val(Str(temp_val) + Str(index))
50 End If
51 End If
52 txtBoard.Text = Str(temp_val)
53 End Sub
54 Private Sub cmdSub_Click()
55 Select Case opt
56 Case Nul: total = temp_val
57 Case Add: total = total + temp_val
58 Case Subb: total = total - temp_val
59 Case Ans: total = temp_val
60 End Select
61 txtBoard = Str(total)
62 temp_val = 0
63 opt = Subb
64 End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 39.12.215.94
※ 文章網址: http://webptt.com/m.aspx?n=bbs/Visual_Basic/M.1405775117.A.E1A.html
※ 編輯: suiming (39.12.215.94), 07/19/2014 21:06:52
1F:→ tsongs:If index = 0 Then zero = True 一行寫完的確不用 End If 07/19 22:23
2F:→ tsongs:Dim opt As Integer ,opt是變數 07/19 22:26
3F:→ tsongs:Select Case 跟if類似 你先讀懂Select Case語法 07/19 22:28
4F:→ tsongs:Select Case opt 07/19 22:31
5F:→ tsongs: Case Nul: total = temp_val 07/19 22:31
6F:→ tsongs:跟 if opt = Nul then 同意思 07/19 22:32
7F:→ tsongs:跟 if opt = Nul then temp_val 同意思 07/19 22:33
8F:→ MOONRAKER:最好你的松肛書上沒有select case用法的咧 07/20 01:45