作者TrueFeeling (昨日之死)
看板Visual_Basic
標題Re: [VB6 ] 計算機
時間Fri Jun 10 15:13:03 2005
慘了.都看不懂T.T,
能不能解說一下整個思路是怎麼架構的,謝啦
還有GoSub,Return這些字我也不知道作用是什麼
Function我看書上(入門書啦)說,Function裡面的架構:
函數名=運算式
所以這種Function的寫法我也看不大懂T.T
※ 引述《fumizuki (小獅子)》之銘言:
: ※ 引述《fumizuki (小獅子)》之銘言:
: Function Eval(s As String)
: Dim p As Integer, op1 As String, op2 As String, o As String
: Static c As Integer: c = c + 1
: If c = 1 Then s = Replace(s, " ", "")
: p = InStr(s, "+")
: If p > 0 Then GoSub SplitProc: Eval = Eval(op1) + Eval(op2): GoTo EndProc
: If s Like "-*" Then p = 2 Else p = 1
: p = InStr(p, s, "-")
: If p > 0 Then
: op1 = Mid(s, p - 1, 1)
: If op1 = "+" Then
: p = p - 1: GoSub SplitProc: Eval = Eval(op1) + Eval(op2): GoTo EndProc
: ElseIf op1 = "-" Then
: p = p - 1: GoSub SplitProc: Eval = Eval(op1) - Eval(op2): GoTo EndProc
: ElseIf op1 = "*" Then
: p = p - 1: GoSub SplitProc: Eval = Eval(op1) * Eval(op2): GoTo EndProc
: ElseIf op1 = "/" Then
: p = p - 1: GoSub SplitProc: Eval = Eval(op1) / Eval(op2): GoTo EndProc
: Else
: GoSub SplitProc: Eval = Eval(op1) + Eval("-" & op2): GoTo EndProc
: End If
: End If
: p = InStr(s, "*")
: If p > 0 Then GoSub SplitProc: Eval = Eval(op1) * Eval(op2): GoTo EndProc
: p = InStr(s, "/")
: If p > 0 Then GoSub SplitProc: Eval = Eval(op1) / Eval(op2): GoTo EndProc
: Eval = Val(s)
: EndProc:
: c = c - 1: Exit Function
: SplitProc:
: op1 = Left(s, p - 1): op2 = Mid(s, p + 1): Return
: End Function
--
少年讀書,如隙中窺月;
中年讀書,如庭中望月;
老年讀書,如臺上玩月。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.162.90.149