第1个回答 2009-04-21
按照你的命名来做:
双击执行除法运算
Private Sub Command1_Click()
Text3.Text = Text1.Text / Text2.Text
Text4.Text = Text1.Text \ Text2.Text
Text5.Text = Text1.Text Mod Text2.Text
End Sub
就可以了
之前应该把所有text的text属性都清空
第2个回答 2009-04-21
'text1为被除数 text2为除数
Private Sub Command1_Click() '执行除法运算
text3 = Val(trim(Text1.Text)) / Val(trim(Text2.Text)) '商
text4 = Val(trim(Text1.Text)) \ Val(trim(Text2.Text)) '整数商
text5 = Val(trim(Text1.Text)) Mod Val(trim(Text2.Text)) '求余
End Sub
第3个回答 2009-04-21
Private Sub Command1_Click()
If IsNumeric(Text1.Text) And IsNumeric(Text2.Text) Then
If Val(Text1.Text) Then
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
Text4.Text = Fix(Val(Text1.Text) / Val(Text2.Text)) '或int()都会删除小数部份而返回剩下的整数
Text5.Text = Val(Text1.Text) Mod Val(Text2.Text)
Else
MsgBox "除数为零!"
End If
Else
MsgBox "被除数或除数输入错误!"
End If
End Sub
第4个回答 2009-04-21
要准备5个文本,5个标签,一个按纽,注意被除数可以为0 但除数不能为0,代码如下
Option Explicit: Dim a As Long, b As Long, c As Long, d As Long
Private Sub Command1_Click()
a = Int(Text1.Text): b = Int(Text2.Text)
c = Int(Text1.Text): d = Int(Text2.Text)
If b <> 0 Then Text4.Text = a \ b
If b = 0 Then MsgBox "除数不能为0"
If Val(Text2.Text) <> 0 Then Text3.Text = Val(Text1.Text) / Val(Text2.Text)
If Val(Text2.Text) = 0 Then MsgBox "除数不能为0"
If d <> 0 Then Text5.Text = c Mod d
If d = 0 Then MsgBox "除数不能为0"
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Label1.Caption = "被除数:"
Label2.Caption = "除数:"
Label3.Caption = "商(/):"
Label4.Caption = "整数商(\):"
Label5.Caption = "余数商(Mod):"
Command1.Caption = "【执行除法运算】"
End Sub
第5个回答 2009-04-21
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Double, d As Integer, e As Integer
a = Text1.Text
b = Text2.Text
c = a / b
d = a \ b
e = a Mod b
Text3.Text = c
Text4.Text = d
Text5.Text = e
End Sub