Results 1 to 4 of 4

Thread: non repeating words

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    32

    Post

    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

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    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.


  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Post

    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).]

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    32

    Post

    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
  •  



Click Here to Expand Forum to Full Width