救命!求WINDOWS简易计算器VB代码!
救命!求WINDOWS简易计算器VB代码!这是老师布置的作业,教都未教好就要我们做,
求各位高手拔刀相助,救救小弟!
我绝不是一个不听课而靠网友打救的人!
我有心学好VB!
--------------------编程问答-------------------- 你这个问题~基本有看过一下书应该都能做出来吧`~~
先看下书吧~兄台~ --------------------编程问答-------------------- 下载频道搜索个就行了 --------------------编程问答-------------------- Dim s
If Text1 = "" Then Exit Sub
On Error GoTo errHandler
Set s = CreateObject("ScriptControl")
s.Language = "VBScript"
Text1 = s.Eval(Text1)
Set s = Nothing
flag = True
Exit Sub
errHandler: Text1 = "E" --------------------编程问答-------------------- 作业题又要锁了 --------------------编程问答-------------------- 转自http://topic.csdn.net/u/20080529/00/573e70c3-e6c5-43be-86da-8654e8fb841b.html
194楼~张郎
'standard project--------------------编程问答-------------------- K,我就准备转那个来着......被抢先了~~~~~~ --------------------编程问答-------------------- 哈~又是迟来的老马 --------------------编程问答-------------------- 做统计时编了一个统计计算器,要我可发给你,很简单的 --------------------编程问答-------------------- 我写了一个工程计算器。 --------------------编程问答-------------------- 这个网上应该很多的
'all in module
Option Explicit
Private Function Eval(ByVal s As String) As Variant
Dim Lb As Long, Rb As Long
Lb = InStrRev(s, "(")
While Lb <> 0
Rb = InStr(Lb, s, ")")
s = Replace(s, Mid$(s, Lb, Rb - Lb + 1), CStr(Eval(Mid$(s, Lb + 1, Rb - Lb - 1))))
Lb = InStrRev(s, "(")
Wend
If IsNumeric(s) Then
Eval = Val(s)
Else
Dim High As Long
High = InStr(s, "+")
If High <> 0 Then
Eval = Eval(Left$(s, High - 1)) + Eval(Right$(s, Len(s) - High))
Exit Function
End If
High = InStrRev(s, "-")
If High <> 0 Then
Eval = Eval(Left$(s, High - 1)) - Eval(Right$(s, Len(s) - High))
Exit Function
End If
High = InStr(s, "*")
If High <> 0 Then
Eval = Eval(Left$(s, High - 1)) * Eval(Right$(s, Len(s) - High))
Exit Function
End If
High = InStrRev(s, "/")
If High <> 0 Then
Eval = Eval(Left$(s, High - 1)) / Eval(Right$(s, Len(s) - High))
Exit Function
End If
High = InStrRev(s, "%")
If High <> 0 Then
Eval = Eval(Left$(s, High - 1)) Mod Eval(Right$(s, Len(s) - High))
Exit Function
End If
High = InStrRev(s, "!=")
If High <> 0 Then
Eval = Eval(Left$(s, High - 1)) <> Eval(Right$(s, Len(s) - High - 1))
Exit Function
End If
High = InStrRev(s, "==")
If High <> 0 Then
Eval = (Eval(Left$(s, High - 1)) = Eval(Right$(s, Len(s) - High - 1)))
Exit Function
End If
End If
End Function
'主函数
Public Sub main()
Dim Expression As String
Expression = "149.5+((100+(6+(90-5*2*2)*4+(1-1))+202)%441)*2*2+0.88+150.5"
MsgBox Eval(Expression)
End Sub
补充:VB , 基础类