1. 首页 > 科技

vb中在text1输入一个数值,text2输入数量,然后text3中随机生成随机数,请问如何实现?谢谢

vb中在text1输入一个数值,text2输入数量,然后text3中随机生成随机数,请问如何实现?谢谢

VB 有text1和text2 两个文本框,在两框中任意输入数字,然后生成3个随机数,我的

Private Sub Form_click()

Randomize

Print Int(Rnd * (b-a+1) + a)

End Sub

产生随机数要用randomize,不然每次产生的都一样

还有正确的格式应该是INT(RND*(b-a+1)+a)

vb怎么产生随机数? 指定随机数从text1至text2,点击按钮输出的3个随机数分别在3个标签中。

text1和text2是否数值或太大之类的错误请自己添加,随便写了一个:

Private Sub Command1_Click()

Dim aa As String

Dim i, j, bb, cc As Long

If Val(Text1) > Val(Text2) Then

cc = Val(Text1) - Val(Text2)

Else

cc = Val(Text2) - Val(Text1)

End If

If cc > 10 Then

bb = 1

For j = 1 To Len(Format(cc, "0"))

bb = bb * 10

Next

End If

Randomize Timer

i = Int(Rnd() * bb) Mod cc

If Val(Text1) > Val(Text2) Then

i = i + Val(Text2)

Else

i = i + Val(Text1)

End If

Label1 = i

Randomize Timer

i = Int(Rnd() * bb) Mod cc

If Val(Text1) > Val(Text2) Then

i = i + Val(Text2)

Else

i = i + Val(Text1)

End If

Label2 = i

Randomize Timer

i = Int(Rnd() * bb) Mod cc

If Val(Text1) > Val(Text2) Then

i = i + Val(Text2)

Else

i = i + Val(Text1)

End If

Label3 = i

End Sub

VB程序 text1输入随机一个数 在text2上得出 8+(text1-1)*3

只要在Text1中输入一个整数,Text2中就会自动出现相对应的数。

Private Sub Text1_Change()

Text2.Text = CLng(Text1.Text) * 3 + 8

End Sub

vb怎样写才能在text1.text上随机出现文字

用inputbox自己输入文字的那种?text1.text=inputbox("输入文字","提示信息",,)