找回密码
 入驻
搜索
查看: 255771|回复: 7

VB计算器源码``

[复制链接]
发表于 2007-6-1 15:58:55 | 显示全部楼层 |阅读模式
Public Class Form1
    Dim sn As String, num As Integer
    Dim flag As Boolean, flag1 As Boolean
    Dim flagcode As Integer

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        Select Case flagcode '运算等号判断过程
            Case 1
                sn = sn + Val(textbox1.Text)
            Case 2
                sn = sn - Val(textbox1.Text)
            Case 3
                sn = sn * Val(textbox1.Text)
            Case 4
                sn = sn / Val(textbox1.Text)
        End Select
        textbox1.Text = sn
    End Sub
    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        Dim back As String
        back = textbox1.Text '退格
        If Len(back) > 1 Then
            textbox1.Text = Mid(back, 1, Len(back) - 1)
        Else
            textbox1.Text = ""
        End If
    End Sub
    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        Dim clean As Boolean '清空
        textbox1.Text = ""
        sn = 0
        clean = False
        flag = False
    End Sub
    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        If textbox1.Text = "" Then textbox1.Text = "0."
        If InStr(textbox1.Text, ".") = 0 Then '小数点,查找有没有小数点
            textbox1.Text = textbox1.Text & "."
            flag = False
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' If flag1 = True Then
        'textbox1.Text = "0不能为除数"  这个失败了,

        If textbox1.Text = "" Then
            textbox1.Text = "0"
            flag = True
        Else
            If Mid(textbox1.Text, 1, 1) = "0" Then
                If Mid(textbox1.Text, 2, 1) = "." Then
                    textbox1.Text = textbox1.Text & "0"
                End If
            Else
                textbox1.Text = textbox1.Text & "0"
            End If
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "1"
        End If
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "2"
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "3"
        End If
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "4"
        End If
    End Sub
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "5"
        End If
    End Sub
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "6"
        End If
    End Sub
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "7"
        End If
    End Sub
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "8"
        End If
    End Sub
    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If flag = True Then
            textbox1.Text = textbox1.Text
        Else
            textbox1.Text = textbox1.Text & "9"
        End If
    End Sub
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        sn = textbox1.Text '加号
        textbox1.Text = ""
        flagcode = 1
    End Sub
    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        sn = textbox1.Text '减号
        textbox1.Text = ""
        flagcode = 2
    End Sub
    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        sn = textbox1.Text '乘号
        textbox1.Text = ""
        flagcode = 3
    End Sub
    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        sn = textbox1.Text '除号
        textbox1.Text = ""
        flagcode = 4
        flag1 = True'用来记录安了除号,不成功~~~
    End Sub
    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        End
    End Sub
    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        sn = textbox1.Text '平方
        textbox1.Text = sn * Val(textbox1.Text)
    End Sub
    Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
        sn = textbox1.Text
        If textbox1.Text < 0 Then
            textbox1.Text = "负数不能开方"
        Else
            textbox1.Text = "我不懂算``^_^``嬉嬉" 'sn / Val(textbox1.Text) '开方运算,哈哈,不懂了``
        End If
    End Sub
    Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
        If textbox1.Text = "0" Then
            textbox1.Text = "0没有倒数"
        Else
            textbox1.Text = 1 / Val(textbox1.Text) '倒数
            flagcode = 7
        End If
    End Sub
    Private Sub Button20_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        If textbox1.Text = "" Then
            textbox1.Text = "-"
        Else
            textbox1.Text = (-1) * Val(textbox1.Text)
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
End Class


有谁懂得的,帮改一下``:handshake :handshake :handshake
 楼主| 发表于 2007-6-1 15:59:51 | 显示全部楼层
有谁懂得的,帮改一下``  :handshake :handshake :handshake

主要是开方和0不能为除数这一点```
回复

使用道具 举报

发表于 2007-6-1 16:32:48 | 显示全部楼层
祈祷吧!
C#我到有点料
回复

使用道具 举报

 楼主| 发表于 2007-6-1 16:52:33 | 显示全部楼层
C#和VB有点相同吧``
回复

使用道具 举报

发表于 2007-6-1 20:36:55 | 显示全部楼层
原帖由 书剑先生 于 2007-6-1 16:52 发表
C#和VB有点相同吧``

C#是类C的编译执行的语言,VB是类PASCAL的解释执行的语言,不一样多于一样
还有你不应该把自己写的代码和编译器生成的代码放在同一文件里,人家看花眼了本来想帮都不原帮了

[ 本帖最后由 zkkpkk 于 2007-6-1 20:38 编辑 ]
回复

使用道具 举报

dfsadsa 该用户已被删除
发表于 2007-6-6 10:19:27 | 显示全部楼层
有一个更简单的
直接用text (加减乘....)text1
   if text1 =0
  msgbox “除数不能0”
   看得懂的就用吧:titter
回复

使用道具 举报

 楼主| 发表于 2007-6-6 19:15:11 | 显示全部楼层

回复 #5 zkkpkk 的帖子

这些都是按键的click事件代码呢

:handshake
回复

使用道具 举报

发表于 2007-6-8 17:15:05 | 显示全部楼层
原帖由 书剑先生 于 2007-6-6 19:15 发表
这些都是按键的click事件代码呢

:handshake

VB6的事件机制是怎么样的?如果是.net通过CLR的它的事件机制应该和C#那套差不多,都是用委托实现的吧,不过就算是VB6也应该和VC6那套宏的机制不同
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 入驻

本版积分规则

QQ|Archiver|手机版|小黑屋|思明论坛

GMT+8, 2024-11-16 19:50 , Processed in 0.050202 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表