作者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