|
-
Nov 30th, 1999, 03:25 AM
#1
Thread Starter
Member
I can write a program that picks random words... but WITHOUT REPEATING ANY OF THEM? How do I do this?
i.e. cat
dog
zebra
elephant
horse
bear
cow
Thanks in advance
ROSE
-
Nov 30th, 1999, 03:53 AM
#2
Fanatic Member
Here is something that I'm sure can be written much easier, but it should work for now (it involves a CommandButton and ListBox)
Code:
Private Sub Command1_Click()
Dim stWord(1 To 7) As String
Dim intWord As Integer
Dim I As Integer
Randomize Timer
stWord(1) = "Cat"
stWord(2) = "Dog"
stWord(3) = "Zebra"
stWord(4) = "Elephant"
stWord(5) = "Horse"
stWord(6) = "Bear"
stWord(7) = "Cow"
intWord = Int((7 - 1 + 1) * Rnd + 1)
For I = 0 To List1.ListCount
If List1.List(I) = stWord(intWord) Then
MsgBox "Word already chosen " & stWord(intWord)
Exit For
ElseIf I = List1.ListCount Then
List1.AddItem stWord(intWord)
MsgBox "Word I chose: " & stWord(intWord)
End If
Next I
End Sub
General idea is to add the word to the listbox and then check if it is in there.
------------------
Visual Basic Programmer (at least I want to be one)
------------------
PolComSoft
You will hear a lot about it.
-
Nov 30th, 1999, 04:08 AM
#3
See MyPost for a method that uses a collection that would be faster.
------------------
Marty
[This message has been edited by MartinLiss (edited 11-30-1999).]
-
Nov 30th, 1999, 08:26 AM
#4
Thread Starter
Member
I copied and pasted your codes, and they worked great! But, I don't want this to get nvolved a listbox. I want a textbox. Thanks all of your help though!
I know a little bit (a very little bit) about using API. I ran the program using the below code... it was very good!!
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_FINDSTRINGEXACT = &H1A2
But, how do you use Prviate Declate Function SendMessage Lib ..... and use a textbox, not listbox?
Thanks!
ROSE
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
|