vb 1到100内产生20个随机数

20个随机数显示在文本框1中,并在文本框1中找出素数,将素数显示在文本框2中

第1个回答  2011-04-28
Private Sub Command1_Click()
For i = 1 To 20
Randomize
Text1 = Text1 & Space(1) & Int(Rnd * 100 + 1)
Next
End Sub

Private Sub Command2_Click()
On Error Resume Next
t = Split(Text1, " ")
For j = 0 To UBound(t) - 1
If t(j) Mod 2 <> 0 Then Text2 = Text2 & t(j) & Space(1)
Next
End Sub本回答被提问者和网友采纳
第2个回答  2011-04-28
Private Sub Command1_Click()
Text1.Text = ""
For i = 1 To 20
Randomize
Text1.Text = Text1.Text & Space(1) & Int(Rnd * 100 + 1)
Next
End Sub

Private Sub Command2_Click()

'On Error Resume Next
Dim i As Integer
Text2.Text = ""
t = Split(Text1.Text, Space(1))
For j = 0 To UBound(t)
Debug.Print t(j)
For i = 2 To Val(t(j)) \ 2
If Val(t(j)) Mod i = 0 Then Exit For
Next
If i > Val(t(j)) \ 2 Then Text2 = Text2 & t(j) & Space(1)
Next
End Sub
相似回答