iso赵强年龄:VB程序完善.会的速进!!

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 20:06:03
在窗体上画一个名称为“Command1”,标题为“计算”的命令按钮,再画5个标签组成一个加法算式,名称为Label5的标签用于显示计算结果,其Caption属性的初始值为空;标签Label5的标题为“计算结果”。运行程序时会自动生成2个随机数,分别显示在加数标签中,如3+2= 。单击“计算”按钮,则将加数标签的值求和,然后计算结果显示在Label5。请填空。

Private Sub Command1_Click()
Dim s As Integer
Label1.caption = str(Int(rnd(1)*10)
Label3.caption = str(Int(rnd(1)*10)
Label5.caption = “”
s=val(Label1.caption)+ val(Label3.caption)
_________________________________________
End Sub

请在横线上填空.

Label5.caption=str(s)

简单点说:
label5.caption=s

复杂点说(如果要运行的更快一点):
Private sub form_load()
Label5.caption = ""
end sub

Private Sub Command1_Click()
Dim x1,x2,s As Integer
Label5.caption = ""
Label1.caption = str(Int(rnd(1)*10)
Label3.caption = str(Int(rnd(1)*10)
x1=val(label1.caption)
x2=val(label2.caption)
s=x1+x2
Label5.caption=s
End sub
_________________________________________
End Sub