VB的 数字选择问题

来源:百度知道 编辑:UC知道 时间:2024/09/21 19:28:54
我现在要做个程序

有2个文本框 1个列表框

我在TEXT1输入9 TEXT2 输入70

要求按下按钮1 会在list1中 随机出现一个 9-70之间的整数.

求高手解答

Private Sub Command1_Click()
Randomize '重置随机数表
a = Val(Text1.Text)
b = Val(Text2.Text)
List1.AddItem (Str(Int((b - a) * Rnd + a)))
End Sub
'rnd产生随机数,int取整,str将数值转换为字符串,val将字符串转换为数字

Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer
a = Val(Text1): b = Val(Text2)
If a < 0 Or b < 0 Then Exit Sub
If a > b Then c = a: a = b: b = c
List1.AddItem a + Int((b - a + 1) * Rnd)
End Sub