作者TrueFeeling (昨日之死)
看板Visual_Basic
標題[VB6 ] 計算機
時間Thu Jun 9 15:58:50 2005
小弟這次作業想做計算機
但是我一直不知道我的程式問題出在哪
有人可以幫在下看一下嗎
現在最大的困難在於要將text輸入的字元轉換成數學表示式
於是我就先嘗試作數字的加減運算,
目前用InStr嘗試將+-號作為分割字串的標準
能請大大們幫我看看哪裡出錯了嗎
Dim A() As Double
Dim B() As String
Dim G() As Double
Private Sub Command1_Click(I As Integer)
Text1.Text = Text1.Text + Command1(I).Caption
End Sub
Private Sub Command2_Click(I As Integer)
Text1.Text = Text1.Text + Command2(I).Caption
End Sub
Private Sub Command3_Click()
H = Text1.Text
C = Len(Text1.Text)
N = 0
D = "+" Or "-"
Do
ReDim Preserve A(N)
ReDim Preserve B(M)
A(N) = InStr(1, H, "D")
If A(N) = 0 Then B(N) = H: Exit Do
B(N) = Left(H, A(N) - 1)
H = Right(H, C - A(N))
N = N + 1
Loop
H = Text1.Text
For I = 0 To N
ReDim Preserve G(N)
G(N) = Val(B(N))
Next I
For I = 0 To N
If Mid(H, A(I), 1) = "+" Then
G(I + 1) = Val(G(I + 1))
Else
G(I + 1) = -Val(G(I + 1))
End If
Next I
Sum = 0
For I = 0 To N
Sum = Sum + G(I)
Next I
Label1.Caption = Sum
End Sub
Private Sub Command4_Click()
Text1.Text = ""
End Sub
Private Sub Command5_Click()
End
End Sub
--
少年讀書,如隙中窺月;
中年讀書,如庭中望月;
老年讀書,如臺上玩月。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.162.88.136
1F:推 fumizuki:command1 和command2 怎麼會有參數... 61.222.155.162 06/09
2F:推 fumizuki:Or 不是這樣用的 61.222.155.162 06/09
3F:推 fumizuki:instr 的第三個參數為"D" ? 61.222.155.162 06/09
4F:推 TrueFeeling:因為那些參數是用來做計算機按鈕的 218.162.88.136 06/09
5F:推 fumizuki:參數不能自訂吧 61.222.155.162 06/09
6F:→ TrueFeeling:可以阿 218.162.88.136 06/09
7F:推 fumizuki:你把你的表單架構說明一下吧 61.222.155.162 06/09
8F:→ fumizuki:事件參數不能自訂... 61.222.155.162 06/09
9F:→ TrueFeeling:只要複製貼上他的Index就會一直增加 218.162.88.136 06/09
10F:→ fumizuki:有一定的規則在... 61.222.155.162 06/09
11F:→ fumizuki:是Index ,不是I 61.222.155.162 06/09
12F:推 fumizuki:把你的表單架構說明一下,或把檔案上傳... 61.222.155.162 06/09
13F:推 TrueFeeling:正在上傳 218.162.88.136 06/09
14F:→ TrueFeeling:一開始是Index 後來我把他改成I 218.162.88.136 06/09
15F:推 fumizuki:這樣你連編譯都不會過... 61.222.155.162 06/09
16F:→ TrueFeeling:D適用來代替+-號的,該不會是這裡錯了吧^^ 218.162.88.136 06/09
17F:→ TrueFeeling:sorry,我是初學者,請大大指導^^ 218.162.88.136 06/09
18F:推 fumizuki:錯很多喔... 61.222.155.162 06/09
19F:→ fumizuki:語法和語意都有錯... 61.222.155.162 06/09