Results 1 to 4 of 4

Thread: random words to a textbox or label

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    32

    Post

    I am creating a sign language program. It provides some kind of feedback and quizzes the users on sign language. There are so many repeating words!! How does a program pick random words without repeating any of them in the textbox or label. It involves a textbox or a label only. Not listbox! Please help me on this problem.
    Thanks in advance!

    ROSE

  2. #2
    Lively Member
    Join Date
    Jul 1999
    Posts
    99

    Post

    You can create predefined words and store them in an array. Create another array to store predefined random numbers. These will define what random word will be next to be used.

    Dim aWords(0 to 3) as String
    Dim ai(0 to 3) as Integer

    'you first need to assign random numbers to 'your array like:

    Dim i as Integer
    For i = 0 to 3
    ai(0) = i
    Next i

    ' Then shuffle
    Dim wRnd as Integer
    For i = 0 to 3
    wRnd = <generate a random number here, sorry forgot the formula>
    Swap(ai(i),ai(wRnd)
    Next i

    ' Here's the code for swap
    Sub Swap(s1$, s2$)
    Dim sTmp as String
    sTmp = s1%
    s1$ = s2$
    s2$ = sTmp
    End Sub

    'you can assign the words like:
    aWords(0) = "Sample1"
    aWords(1) = "Sample2"
    aWords(2) = "Sample3"
    aWords(3) = "Sample4"

    'and use them in a random manner like:
    Dim i as integer
    For i = 0 to 3
    txt.Text = aWords(ai(i))
    Next i

    did you get me or i did'nt get you?

    [This message has been edited by Tonio169 (edited 12-02-1999).]

  3. #3
    Lively Member
    Join Date
    Jun 1999
    Location
    Ireland
    Posts
    96

    Post

    I am assuming you have an array, something like
    strMyWord(0 to 99) as String
    and this array is full of words.

    Then create another array.
    booMyWord(0 to 99) as Boolean
    and do something like

    n = Int(Rnd() * 100)
    lblWord.Caption = strWord(n)
    Do While booMyWord(n)
    n = Int(Rnd() * 100)
    If Not booWord(n) then
    lblWord.Caption = strWord(n)
    EndIf
    Wend
    booWord(n) = True

    This will place a different random word from the list into the lblWord.Caption Label
    Don't forget to use

    Randomize Timer

    in your form load, or the random sequence will be the same every time you run the program.

    Hope this helps,
    Steve.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    32

    Post

    Hi,

    I cut and pasted the codes you all posted. The first code.... not sure what to do. The second code.... there are many repeating words.

    Here is my code. Please tell me how to generate random words without repeating any of them!

    Thanks,
    ROSE


    Option Explicit
    Dim number As Integer
    Dim definitionword(999) As String
    Dim wordstring As String
    Dim labelp As String
    Dim counter As Integer
    Dim number1 As Integer
    Dim test As String
    Dim name As String
    dim label

    Private Sub Command1_Click()
    Dim i As Integer
    If UCase(text1.Text) = UCase(label Then 'to test if match
    Label3.Caption = "Right" 'display right or wrong
    Else
    Label3.Caption = "Wrong"
    End If

    Randomize Timer 'randomize
    number1 = Int(Rnd * number)
    label = dword(definitionword(number1)) 'randomly words

    Label2.Caption = labelp 'displays the definition
    imgSign.Picture = LoadPicture(App.Path & "\images\" & label & ".gif") 'load images
    Label1.Caption = label 'displays the word
    End Sub

    Private Sub Form_Load()
    Open App.Path & "\description.txt" For Input As #1
    Do While Not EOF(1)
    Line Input #1, definitionword(counter)
    counter = counter + 1
    Loop
    Close #1
    number = counter
    End Sub

    Private Function dword(word$) As String
    name = Trim$(word)
    test = InStr(name, " ")
    dword = Left$(name, test - 1) 'get first word from the file
    labelp = Right$(name, (Len(name) - test)) 'get the phrases after the first word from the file
    End Function

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