|
-
May 31st, 2002, 02:09 PM
#1
Thread Starter
Fanatic Member
How can you msgbox a random entry in a listbox?
and add a 4 digit random number to it?
-
May 31st, 2002, 02:11 PM
#2
-
May 31st, 2002, 02:12 PM
#3
Stuck in the 80s
Msgbox random entry in listbox:
VB Code:
Dim iRand As Integer
Randomize
iRand = rnd * (List1.ListCount - 1)
MsgBox List1.List(iRand)
Add a random 4-didget number:
VB Code:
Dim sRand As String
Randomize
For i = 1 to 4
sRand = sRand & str(int(rnd * 9) + 1)
Next
Or something like that.
-
May 31st, 2002, 02:13 PM
#4
Dont suppose you wanna give more details 
Theres a command called Rand(), will do what you want, alongside a command called MsgBox.
-
May 31st, 2002, 02:15 PM
#5
Stuck in the 80s
Example:
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim iRand As Integer
Randomize
iRand = Rnd * (List1.ListCount - 1)
'select the random item:
List1.Selected(iRand) = True
MsgBox List1.List(iRand)
End Sub
Private Sub Form_Load()
Dim sRand As String, i As Integer, j As Integer
Randomize
For i = 1 To 22
For j = 1 To 4
sRand = sRand & Trim(Str(Int(Rnd * 9) + 1))
Next
List1.AddItem sRand
sRand = ""
Next
End Sub
-
May 31st, 2002, 02:21 PM
#6
Code:
Function ShowList_RndNum(LstBox as ListBox) as string
dim NumItems as integer,ThisItem as integer
dim ThatNum as integer,Ret_Val as string
NumItems=LstBox.ListCount-1
ThisItem = int(Rnd()*NumItems)
ThatNum = int(Rnd()*9999)
Ret_Val = right$("0000"+ltrim$(str$(ThatNum)),4)
Ret_Val = LstBox.List(ThisItem) & " " & Ret_Val
Xit_ShowList_RndNum:
ShowList_RndNum=Ret_Val
End Function
Is this what you wanted?????
ShowList_RndNum will return a string comprised of the randomly
selected list item and a randomly selected number between 0000-
9999.
-
May 31st, 2002, 02:24 PM
#7
Stuck in the 80s
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|