十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Option Explicit
创新互联建站专注于商丘企业网站建设,成都响应式网站建设公司,电子商务商城网站建设。商丘网站建设公司,为商丘等地区提供建站服务。全流程按需策划,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务
Private Sub Command1_Click()
Text3.Text = "" '余数
If IsNumeric(Text1.Text) = False Then
MsgBox "被除数不是数字,请重新输入"
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
If IsNumeric(Text2.Text) = False Then
MsgBox "除数不是数字,请重新输入"
Text2.Text = ""
Text2.SetFocus
Exit Sub
End If
If Text2.Text = 0 Then
MsgBox "除数不能为0,请重新输入"
Text2.Text = ""
Text2.SetFocus
Exit Sub
End If
Text3.Text = Val(Text1.Text) Mod Val(Text2.Text)
if left(text3.text,1)="." then text3.text="0" text3.text '把这行加上
End Sub
Private Sub Command1_Click()
Dim a, b, c As Single '定义变量a,b,c
a = Val(Text1.Text) '取的第一个除数并放到存储单元a中
b = Val(Text2.Text) '取的第二个除数并放到存储单元b中
'----
IF b = 0 Then
Msgbox "除数不能为0或空"
exit sub
End If
'----
c = a / b '把两个除数转换数字后相除,并把计算的结果存放到存储单元c中
Label2.Caption = c '把存储单元c中的值,显示在标签中
End Sub
先在form上建立三个textbox,分别为textbox1,textbox2,textbox3,再建立四个按钮,分别为cmdplus,cmdminus,cmdmultiple,cmddivide,代码如下:
Private Sub cmdplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdplus.Click
Dim a As Integer
Dim b As Integer
a = TextBox1.Text
b = TextBox2.Text
TextBox3.Text = a + b
End If
Private Sub cmdminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdminus.Click
Dim a As Integer
Dim b As Integer
a = TextBox1.Text
b = TextBox2.Text
TextBox3.Text = a - b
End If
Private Sub cmdmultiple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdmultiple.Click
Dim a As Integer
Dim b As Integer
a = TextBox1.Text
b = TextBox2.Text
TextBox3.Text = a * b
End If
Private Sub cmddivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddivide.Click
Dim a As Integer
Dim b As Integer
a = TextBox1.Text
b = TextBox2.Text
TextBox3.Text = a / b
End If