[VB6 ] 計算機
小弟這次作業想做計算機
但是我一直不知道我的程式問題出在哪
有人可以幫在下看一下嗎
現在最大的困難在於要將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
推
61.222.155.162 06/09, , 1F
61.222.155.162 06/09, 1F
推
61.222.155.162 06/09, , 2F
61.222.155.162 06/09, 2F
推
61.222.155.162 06/09, , 3F
61.222.155.162 06/09, 3F
推
218.162.88.136 06/09, , 4F
218.162.88.136 06/09, 4F
推
61.222.155.162 06/09, , 5F
61.222.155.162 06/09, 5F
→
218.162.88.136 06/09, , 6F
218.162.88.136 06/09, 6F
推
61.222.155.162 06/09, , 7F
61.222.155.162 06/09, 7F
→
61.222.155.162 06/09, , 8F
61.222.155.162 06/09, 8F
→
218.162.88.136 06/09, , 9F
218.162.88.136 06/09, 9F
→
61.222.155.162 06/09, , 10F
61.222.155.162 06/09, 10F
→
61.222.155.162 06/09, , 11F
61.222.155.162 06/09, 11F
推
61.222.155.162 06/09, , 12F
61.222.155.162 06/09, 12F
推
218.162.88.136 06/09, , 13F
218.162.88.136 06/09, 13F
→
218.162.88.136 06/09, , 14F
218.162.88.136 06/09, 14F
推
61.222.155.162 06/09, , 15F
61.222.155.162 06/09, 15F
→
218.162.88.136 06/09, , 16F
218.162.88.136 06/09, 16F
→
218.162.88.136 06/09, , 17F
218.162.88.136 06/09, 17F
推
61.222.155.162 06/09, , 18F
61.222.155.162 06/09, 18F
→
61.222.155.162 06/09, , 19F
61.222.155.162 06/09, 19F
討論串 (同標題文章)
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章