| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4666 人关注过本帖
标题:求教,四则运算计算器如何实现?
只看楼主 加入收藏
hyhhd
Rank: 2
等 级:论坛游民
威 望:1
帖 子:502
专家分:44
注 册:2006-5-12
收藏
得分:0 
不过我觉得我的方法可能笨了。

2008-09-13 00:47
hyhhd
Rank: 2
等 级:论坛游民
威 望:1
帖 子:502
专家分:44
注 册:2006-5-12
收藏
得分:0 
Private Sub Operator_Click(Index As Integer)
    If C.OperateState = 函数 Then
        Exit Sub
   
    End If
   
'    If C.OperateState = 计算 And Check3.Value = 0 Then
'        Text1(0) = ""
'        C.OperateState = 无
   
   
    If Index <= 9 Then
        If (C.OperateState = 计算 Or C.OperateState = 无) And JG <> "" And Check3.Value = 1 Then
            Text1(0) = JG
            C.OperateState = 数字
            
        Else
            C.OperateState = C.GetOperationState(Text1(0))
            
        End If
        
        
        If Index = 2 Then   '''如果为“-”号
            If C.OperateState = 无 Then
                Text1(0) = Operator(Index).Caption
                C.OperateState = 正负号
                IsExistDot = False
            
            ElseIf C.OperateState >= 20 And C.OperateState <= 29 Then      '''双目可加
                Text1(0) = Text1(0) & Operator(Index).Caption
                C.OperateState = 正负号
                IsExistDot = False
            
            ElseIf C.OperateState >= 30 And C.OperateState <= 41 Then      '''单目可加
                Text1(0) = Text1(0) & " " & Operator(Index).Caption & " "
                C.OperateState = 减法运算
                IsExistDot = False
               
            ElseIf C.OperateState <= 11 And C.OperateState <> 正负号 Then
                If C.OperateState = 3 Then
                    Text1(0) = Text1(0) & Operator(Index).Caption
                    C.OperateState = 正负号
                    
                Else
                    Text1(0) = Text1(0) & " " & Operator(Index).Caption & " "
                    C.OperateState = 减法运算
                    
                End If
                IsExistDot = False
               
            Else
            
            End If
               
        Else    '''如果前面为无、数字、小数点、阶乘
            If Index = 8 Then
                If C.OperateState = 无 Then
                    Text1(0) = Operator(Index).Caption & " "
                    C.OperateState = 非运算
                    IsExistDot = False
                    
                ElseIf C.OperateState >= 20 And C.OperateState <= 42 And C.OperateState <> 阶乘运算 Then
                    Text1(0) = Text1(0) & Operator(Index).Caption & " "
                    C.OperateState = 非运算
                    IsExistDot = False
                    
                Else
                    
               
                End If
               
            Else
                If C.OperateState = 阶乘运算 Or C.OperateState > 无 And C.OperateState <= 10 And C.OperateState <> 正负号 Or C.OperateState = 后括号 Then
                    Text1(0) = Text1(0) & " " & Operator(Index).Caption & " "
                    C.OperateState = C.GetOperationState(Operator(Index).Caption)
                    IsExistDot = False
                    
               
                    
                ElseIf C.OperateState = 无 And (JG <> "" Or JG <> "0.") And Check3.Value = 1 Then
                    Text1(0) = Val(JG) & " " & Operator(Index).Caption & " "
                    C.OperateState = C.GetOperationState(Operator(Index).Caption)
                    IsExistDot = False
                    
                Else
               
                End If
            
            End If
            
        End If
   
    Else    ''''单目运算符
        If Index = 21 Then
            C.OperateState = C.GetOperationState(Text1(0))
            
            If C.OperateState = 数字 And C.IsExistDot = False Then
                Text1(0) = Text1(0) & Operator(Index).Caption
                C.OperateState = 阶乘运算
                IsExistDot = False
            
            End If
        ElseIf (C.OperateState = 计算 Or C.OperateState = 无) And JG <> "" And Check3.Value = 1 Then
            Text1(0) = Operator(Index).Caption & " " & Val(JG) & " "
            Text1(1) = "0."
            C.OperateState = C.GetOperationState(Operator(Index).Caption)
            IsExistDot = False
                    
        ElseIf (C.OperateState <> 后括号 And C.OperateState <> 数字 And C.OperateState <> 小数点 And C.OperateState <> 单目运算 Or C.OperateState = 无 And JG = "") And C.OperateState <> 计算 Then
            If C.OperateState = 无 Then
                Text1(0) = Operator(Index).Caption & " "
                Text1(1) = "0."
               
            Else
                Text1(0) = Text1(0) & " " & Operator(Index).Caption & " "
               
            End If
            
            C.OperateState = C.GetOperationState(Operator(Index).Caption)
            
            IsExistDot = False
            
        
        End If
        
    End If
   
    If (C.OperateState >= 20 And C.OperateState <= 42) And C.ErrorString <> "" Then
        Text1(1) = "0."
   
    End If
   
End Sub

2008-09-13 00:58
aspd199
Rank: 1
来 自:宇宙
等 级:新手上路
威 望:1
帖 子:62
专家分:0
注 册:2008-4-17
收藏
得分:0 
引用microsoft script control
private sub form_load()
set a = New scriptcontrol
a.language = "VBScript"
msgbox a.eval("3*4+2*1-5/(2+3)+3")
end sub

8620高手挑战站
http://
2008-09-13 01:27
hyhhd
Rank: 2
等 级:论坛游民
威 望:1
帖 子:502
专家分:44
注 册:2006-5-12
收藏
得分:0 
"microsoft script control"干什么用的?

2008-09-13 13:44
快速回复:求教,四则运算计算器如何实现?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017721 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved