求VB题的答案,请高手指教~

来源:百度知道 编辑:UC知道 时间:2024/06/21 18:17:53
在文本框中输入除数和被除数,单击【执行除法运算】按钮时,在下面三个文本框里分别显示计算结果。

界面如下:
=======================

除数:
被除数:
商(/):
整数商(\):
余数商(Mod):

【执行除法运算】

'text1为被除数 text2为除数
Private Sub Command1_Click() '执行除法运算
text3 = Val(Text1.Text) / Val(Text2.Text) '商
text4 = Val(Text1.Text) \ Val(Text2.Text) '整数商
text5 = Val(Text1.Text) Mod Val(Text2.Text) '求余
End Sub

要准备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.T