and add a 4 digit random number to it?
Printable View
and add a 4 digit random number to it?
Yes
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.
Dont suppose you wanna give more details :)
Theres a command called Rand(), will do what you want, alongside a command called MsgBox.
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
Is this what you wanted?????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
ShowList_RndNum will return a string comprised of the randomly
selected list item and a randomly selected number between 0000-
9999.
:confused: