Log in

View Full Version : Sentence Generator using Array


lamlamlamiaaa
Feb 13, 2012, 04:23 PM
I want to create a random sentence generator. The user will enter 20 random words in a textbox, one at a time. And then with those 20 words, a label will pop up with 7 of the 20 words. The sentence doesn't have to make sense.

Help!

Rodcane
Jun 7, 2014, 10:33 AM
This may not be exactly what you're looking for but it works.
There are 4 components placed on the form:
* Label1. Caption = "Enter a word. Press enter key"
* Text1.Text Used to accept entries.
* List1.List Used to store entries
* Quit.Click Used to exit program

Dim Digit(20), Swan, Collect$
Private Sub Quit_Click()
End
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
For Cake = 1 To 20
If Trim$(Text1.Text) <> "" And List1.ListCount < 21 Then
List1.AddItem Trim$(Text1.Text): Text1.Text = ""
Text1.SetFocus
End If
Next Cake
If List1.ListCount = 20 Then
For Cycle = 1 To 20
LUNAR:
Picky = Int(20 * Rnd) + 1
Collect$ = Collect$ & List1.List(Picky) & vbCrLf
For Recheck = 1 To 20
If Picky = Digit(Recheck) Then GoTo LUNAR
Next Recheck: Digit(Cycle) = Picky
Swan = Swan + 1
If Swan = 7 Then GoTo RESULTS
Next Cycle
RESULTS:
Message$ = "Randomly selected 7 words " & vbCrLf & vbCrLf & Collect$
MsgBox Message$, vbInformation, " Randomly Selected 7 Of Your Words ": Collect$ = "": Swan = 0
End If
End Sub