跪求VB程序!!!急急急

2024-12-18 18:05:48
推荐回答(4个)
回答1:

'在窗体中添加Text1、Text2、Text3、Label1、Label2、Command1、Command2等控件

'数据生成部分
Private Sub Command1_Click()
Randomize
Text1.Text = Int(101 * Rnd) '使用Rnd函数
Text2.Text = Int(101 * Rnd)
End Sub

'结果判断部分
Private Sub Command2_Click()
Dim a As Single, b As Single, c As Single

a = Val(Trim(Text1.Text))
b = Val(Trim(Text2.Text))
c = Val(Trim(Text3.Text))
If c = 0 Then Text3.Text = 0

If Len(Trim(Text3.Text)) = 0 Then MsgBox "请输入计算结果!", , "四则计算": Exit Sub '使用MsgBox函数

Select Case Trim(Label1.Caption)
Case "+"
If c = a + b Then MsgBox "计算结果正确", , "四则计算" Else MsgBox "计算结果错误", , "四则计算"
Case "-"
If c = a - b Then MsgBox "计算结果正确", , "四则计算" Else MsgBox "计算结果错误", , "四则计算"
Case "*"
If c = a * b Then MsgBox "计算结果正确", , "四则计算" Else MsgBox "计算结果错误", , "四则计算"
Case "/"
If b = 0 Then
MsgBox "除数不能为0!", , "四则计算"
Else
'c = Val(Format(c, ".00"))
If Abs(c - a / b) < 0.001 Then MsgBox "计算结果正确", , "四则计算" Else MsgBox "计算结果错误", , "四则计算"
End If
Case Else
MsgBox "没有这样的运算符!请使用+、-、*、/等运算符!", , "四则计算"
End Select

End Sub

'控件初始化部分
Private Sub Form_Activate()

Label1.AutoSize = True
Label2.AutoSize = True
Label1.Caption = "/" '改变运算符,加号用+,减号用-,乘号用*,除号用/
Label2.Caption = "="

Label1.Left = Text1.Left + Text1.Width
Label1.Top = Text1.Top - (Label1.Height - Text1.Height) / 2
Text2.Left = Label1.Left + Label1.Width
Text2.Top = Label1.Top - (Text2.Height - Label1.Height) / 2
Label2.Left = Text2.Left + Text2.Width
Label2.Top = Text2.Top - (Label2.Height - Text2.Height) / 2
Text3.Left = Label2.Left + Label2.Width
Text3.Top = Label2.Top - (Text3.Height - Label2.Height) / 2

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Command1.Caption = "随机"
Command2.Caption = "判断"
End Sub

回答2:

这些函数我在VB中都没看到过,不知道是不是你自创的

回答3:

这么简单的问题,看上1天的书全都会了

回答4:

在Button1中写
Randomize()
TextBox1.Text = Int(100 * Rnd() + 0)
TextBox2.Text = Int(100 * Rnd() + 0)
在Button2中写
If TextBox3.Text <> "" Then
If Val(TextBox3.Text) = Val(TextBox1.Text) + Val(TextBox2.Text) Then
MessageBox.Show("结果正确")
Else
MessageBox.Show("结果错误")
End If
End If

不过不知道在套用到Web中可不可以