Click to See Complete Forum and Search --> : non repeating words
Rose
Nov 30th, 1999, 02:25 AM
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
QWERTY
Nov 30th, 1999, 02:53 AM
Here is something that I'm sure can be written much easier, but it should work for now (it involves a CommandButton and ListBox)
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.
MartinLiss
Nov 30th, 1999, 03:08 AM
See MyPost (http://www.vb-world.net/ubb/Forum1/HTML/010615.html) for a method that uses a collection that would be faster.
------------------
Marty
[This message has been edited by MartinLiss (edited 11-30-1999).]
Rose
Nov 30th, 1999, 07:26 AM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.