| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1123 人关注过本帖
标题:如何用VB.NET设计一个计算器,简单点的,就和附件里的那模式
只看楼主 加入收藏
feifei496349
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-6-5
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
如何用VB.NET设计一个计算器,简单点的,就和附件里的那模式
简易计算器
实现功能:
实现一个计算器的功能,要求可以实现简单的浮点运算,复杂函数运算功能不要求。
具体实现功能包括数字(0-9)、小数点、运算符(加、减、乘、除、等号)、函数(取消输入CE、重置C、撤销←),具体界面及实现功能可参考Windows附件中的计算器或自行设计。
    实验要求:
    1、初始值为0
    2、小数点不能重复输入
    3、高位数的0不出现
    4、    除数不为零
    5、可连续运算
    6、程序代码要求有注释


搜索更多相关主题的帖子: 小数点 Windows 计算器 如何 
2012-06-05 10:41
mp654k
Rank: 2
等 级:论坛游民
帖 子:74
专家分:70
注 册:2011-7-9
收藏
得分:0 
Public Class Form1
    Dim dengyu, yunsuanfu, xiaoshudian, i As Integer, op As String, op1, op2 As Double
   
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If TextBox1.Text = "还未输入过任何数!" Or TextBox1.Text = "请输入数!" Or TextBox1.Text = "0" Then
            TextBox1.Text = "1"
        Else
            If dengyu = 0 And yunsuanfu = 0 Then
                TextBox1.Text = TextBox1.Text & "1"
            Else
                TextBox1.Text = "1"
                dengyu = 0
                yunsuanfu = 0
            End If
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dengyu = 0
        yunsuanfu = 0
        xiaoshudian = 0
        op = ""
        op1 = 0
        TextBox1.Text = "还未输入过任何数!"
    End Sub
    Private Sub danshuzishuru(ByVal i)
        If TextBox1.Text = "还未输入过任何数!" Or TextBox1.Text = "请输入数!" Or TextBox1.Text = "0" Then
            TextBox1.Text = i
        Else
            If dengyu = 0 And yunsuanfu = 0 Then
                TextBox1.Text = TextBox1.Text & i
            Else
                TextBox1.Text = i
                dengyu = 0
                yunsuanfu = 0
            End If
        End If
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        danshuzishuru(2)
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        danshuzishuru(3)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        danshuzishuru(4)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        danshuzishuru(5)
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        danshuzishuru(6)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        danshuzishuru(7)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        danshuzishuru(8)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        danshuzishuru(9)
    End Sub

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        End
    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        dengyu = 0
        yunsuanfu = 0
        xiaoshudian = 0
        op = ""
        op1 = 0
        TextBox1.Text = "还未输入过任何数!"
        Label4.Text = "状态正常"
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If TextBox1.Text = "还未输入过任何数!" Or TextBox1.Text = "请输入数!" Then
            TextBox1.Text = "请输入数!"
        Else
            If yunsuanfu = 0 Then
                op1 = TextBox1.Text

            Else
                op1 = op1
            End If
            op = "+"
            TextBox1.Text = "+"
            xiaoshudian = 0
            yunsuanfu = 1
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If TextBox1.Text = "还未输入过任何数!" Or TextBox1.Text = "请输入数!" Then
            TextBox1.Text = "请输入数!"
        Else
            If yunsuanfu = 0 Then
                op1 = TextBox1.Text

            Else
                op1 = op1
            End If
            op = "-"
            TextBox1.Text = "-"
            xiaoshudian = 0
            yunsuanfu = 1
        End If
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        If TextBox1.Text = "还未输入过任何数!" Or TextBox1.Text = "请输入数!" Then
            TextBox1.Text = "请输入数!"
        Else
            If yunsuanfu = 0 Then
                op1 = TextBox1.Text

            Else
                op1 = op1
            End If
            op = "*"
            TextBox1.Text = "*"
            xiaoshudian = 0
            yunsuanfu = 1
        End If
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        If TextBox1.Text = "还未输入过任何数!" Or TextBox1.Text = "请输入数!" Then
            TextBox1.Text = "请输入数!"
        Else
            If yunsuanfu = 0 Then
                op1 = TextBox1.Text

            Else
                op1 = op1
            End If
            op = "/"
            TextBox1.Text = "/"
            xiaoshudian = 0
            yunsuanfu = 1
        End If
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        If TextBox1.Text = "还未输入过任何数!" Or TextBox1.Text = "请输入数!" Or dengyu = 1 Or yunsuanfu = 1 Then
            TextBox1.Text = "0."
            xiaoshudian = 1
            dengyu = 0
            yunsuanfu = 0
        Else

            If xiaoshudian = 0 Then
                TextBox1.Text = TextBox1.Text & "."
                xiaoshudian = 1
                dengyu = 0
                yunsuanfu = 0
            End If
        End If



    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click

1:      Select Case op
            Case "+"
                TextBox1.Text = op1 + TextBox1.Text
                dengyu = 1
                xiaoshudian = 0
            Case "-"
                TextBox1.Text = op1 - TextBox1.Text
                dengyu = 1
                xiaoshudian = 0
            Case "*"
                TextBox1.Text = op1 * TextBox1.Text
                dengyu = 1
                xiaoshudian = 0
            Case "/"
                If TextBox1.Text = "0" Or TextBox1.Text = "0." Or TextBox1.Text = "/" Then
                    Label4.Text = "除数不能为0!已经自动清零!"
                    dengyu = 0
                    yunsuanfu = 0
                    xiaoshudian = 0
                    op = ""
                    op1 = 0
                    TextBox1.Text = "还未输入过任何数!"
                Else
                    TextBox1.Text = op1 / TextBox1.Text
                    dengyu = 1
                    xiaoshudian = 0

                End If



        End Select
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        If TextBox1.Text = "还未输入过任何数!" Or TextBox1.Text = "请输入数!" Or dengyu = 1 Or yunsuanfu = 1 Or TextBox1.Text = "0" Then
            TextBox1.Text = "0"
            dengyu = 0
            yunsuanfu = 0
        Else
            TextBox1.Text = TextBox1.Text & "0"

        End If
    End Sub
End Class
2012-06-08 20:11
mp654k
Rank: 2
等 级:论坛游民
帖 子:74
专家分:70
注 册:2011-7-9
收藏
得分:20 
以前初学时弄过一个简单的.
2012-06-08 20:12
g12339645
Rank: 2
等 级:论坛游民
帖 子:14
专家分:42
注 册:2011-6-17
收藏
得分:0 
混分可以不?
2012-06-21 19:28
ddl205
Rank: 1
等 级:新手上路
帖 子:8
专家分:8
注 册:2012-11-13
收藏
得分:0 
也是初学的,也在找这方面例子
2012-11-21 16:21
快速回复:如何用VB.NET设计一个计算器,简单点的,就和附件里的那模式
数据加载中...
 
   



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

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