书剑先生 发表于 2007-6-1 15:58:55

VB计算器源码``

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不能为除数这一点```

lanteng 发表于 2007-6-1 16:32:48

祈祷吧!
C#我到有点料

书剑先生 发表于 2007-6-1 16:52:33

C#和VB有点相同吧``

zkkpkk 发表于 2007-6-1 20:36:55

原帖由 书剑先生 于 2007-6-1 16:52 发表 http://172.16.1.236/images/common/back.gif
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

zkkpkk 发表于 2007-6-8 17:15:05

原帖由 书剑先生 于 2007-6-6 19:15 发表 http://172.16.1.236/images/common/back.gif
这些都是按键的click事件代码呢

:handshake
VB6的事件机制是怎么样的?如果是.net通过CLR的它的事件机制应该和C#那套差不多,都是用委托实现的吧,不过就算是VB6也应该和VC6那套宏的机制不同
页: [1]
查看完整版本: VB计算器源码``