作者TrueFeeling (昨日之死)
看板Visual_Basic
标题Re: [VB6 ] 计算机
时间Tue Jun 14 00:19:36 2005
刚刚下午试着加入绝对值的计算功能
不知道哪里做错了
(不过回圈那边应该没有错,因为没有用绝对值来跑的时候是OK的!!!)
===
程式草稿:
http://rapidshare.de/files/2358986/AAA.rar.html
===
Private Sub Command1_Click(Index As Integer)
If Option1(0).Value Then
Text1.Text = Text1.Text & Index
Text5.Text = Text5.Text & Index
ElseIf Option1(1).Value Then
Text2.Text = Text2.Text & Index
ElseIf Option1(2).Value Then
Text3.Text = Text3.Text & Index
ElseIf Option1(3).Value Then
Text4.Text = Text4.Text & Index
End If
End Sub
Private Sub Command10_Click()
If Option1(0).Value Then
Text1.Text = Text1.Text & Command10.Caption
Text5.Text = Text5.Text & Command10.Caption
ElseIf Option1(1).Value Then
Text2.Text = Text2.Text & Command10.Caption
ElseIf Option1(2).Value Then
Text3.Text = Text3.Text & Command10.Caption
ElseIf Option1(3).Value Then
Text4.Text = Text4.Text & Command10.Caption
End If
End Sub
Private Sub Command2_Click(Index As Integer)
Text1.Text = Text1.Text & Command2(Index).Caption
Text5.Text = Text5.Text & Command2(Index).Caption
End Sub
Private Sub Command3_Click()
Label1.Caption = G(Text1.Text)
End Sub
Function G(s As String)
Dim p As Integer, F As Integer, I As String, J As String
Dim a As String, o As String, b As String, u As Integer
Static c As Integer: c = c + 1
If c = 1 Then s = Replace(s, " ", "")
o = "+": GoSub L20
If p > 0 Then GoSub L40: G = G(I) + G(J): GoTo L10
o = "-": GoSub L20
If p > 0 Then GoSub L40: G = G(I) - G(J): GoTo L10
o = "*": GoSub L20
If p > 0 Then GoSub L40: G = G(I) * G(J): GoTo L10
o = "/": GoSub L20
If p > 0 Then GoSub L40: G = G(I) / G(J): GoTo L10
o = "^": GoSub L20
If p > 0 Then
GoSub L40
If I Like "-*" Then
G = -G(Mid(I, 2)) ^ G(J)
Else
G = G(I) ^ G(J)
End If
GoTo L10
End If
o = "Abs": GoSub L30
If p = 0 Then
ElseIf p = 1 Then
GoSub L50: G = G(I & J)
ElseIf p > 1 Then
a = Mid(s, p - 1, 1)
If a = "+" Then
GoSub L60: G = G(I & J)
ElseIf a = "-" Then
GoSub L70: G = G(I & J)
Else
GoSub L50: G = G(I & J)
End If
GoTo L10
End If
G = Val(s)
L10:
c = c - 1: Exit Function
L20:
p = Len(s) + 1
u = 0
Do
Do
p = InStrRev(s, o, p - 1)
If o = "^" Then Exit Do
If p <= 1 Then
F = 0 And u = u + 1
Else
a = Mid(s, p - 1, 1)
If a = "+" Or a = "-" Or a = "*" Or a = "/" Or a = "^" Then
F = 1 And u = 0
Else
F = 0 And u = u + 1
End If
End If
Loop While F = 1
If p <= 3 Then F = 0 And u = u + 1: Exit Do
Do
p = InStrRev(s, o, p - 3)
If p <= 3 Then
F = 0 And u = u + 1
Else
b = Mid(s, p - 3, 3)
If b = "Abs" Then
F = 1 And u = 0
Else
F = 0 And u = u + 1
End If
End If
Loop While F = 1
Loop While u < 2
If p = 1 Then p = 0
Return
L30:
p = InStrRev(s, o): Return
L40:
I = Left(s, p - 1): J = Mid(s, p + 1): Return
L50:
I = Left(s, p - 1): J = Abs(Val(Mid(s, s + 3))): Return
L60:
I = Left(s, p - 1): J = Abs(Val(Mid(s, s + 4))): Return
L70:
I = Left(s, p - 1): J = -Abs(Val(Mid(s, s + 4))): Return
End Function
Private Sub Command4_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Label1.Caption = ""
End Sub
Private Sub Command5_Click()
End
End Sub
Private Sub Command6_Click()
If Option1(0).Value Then
Text1.Text = Text1.Text + Text2.Text
Text5.Text = Text5.Text + "X"
Else
End If
End Sub
Private Sub Command7_Click()
If Option1(0).Value Then
Text1.Text = Text1.Text + Text3.Text
Text5.Text = Text5.Text + "Y"
Else
End If
End Sub
Private Sub Command8_Click()
If Option1(0).Value Then
Text1.Text = Text1.Text + Text4.Text
Text5.Text = Text5.Text + "Z"
Else
End If
End Sub
Private Sub Command9_Click()
If Option1(0).Value Then
If Len(Text1.Text) >= 1 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
Text5.Text = Left(Text5.Text, Len(Text5.Text) - 1)
Else
End If
ElseIf Option1(1).Value Then
If Len(Text2.Text) >= 1 Then
Text2.Text = Left(Text2.Text, Len(Text2.Text) - 1)
Else
End If
ElseIf Option1(2).Value Then
If Len(Text3.Text) >= 1 Then
Text3.Text = Left(Text3.Text, Len(Text3.Text) - 1)
Else
End If
ElseIf Option1(3).Value Then
If Len(Text4.Text) >= 1 Then
Text4.Text = Left(Text4.Text, Len(Text4.Text) - 1)
Else
End If
End If
End Sub
--
少年读书,如隙中窥月;
中年读书,如庭中望月;
老年读书,如台上玩月。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.162.72.67
※ 编辑: TrueFeeling 来自: 218.162.72.67 (06/14 00:42)
1F:推 fumizuki:Mid(s, s + 3) ?????? 210.58.156.43 06/14