[RESOLVED] Grabbing 5 Random Words from TXT File
Does anyone have any code that will allow me to grab 5 random words from TXT file? (and send to text1 for example)
I would like to be able to change it to 20 words from a file or just one.
Here is a code that I have that currently grabs ONE random line from a txt file:
Code Code:
Public Function GetQuote(QuoteFile As String) As String
Dim strData() As String, strWholeFile As String
Dim intFileNum As Integer
intFileNum = FreeFile
'Allocate buffer and read in complete file
strWholeFile = Space(FileLen(QuoteFile))
Open QuoteFile For Binary As #intFileNum
Get #intFileNum, , strWholeFile
Close intFileNum
'Remove carriage returns
strWholeFile = Replace(strWholeFile, vbCr, "")
'Convert into Array
strData = Split(strWholeFile, vbLf)
'Randomly select element from array
Randomize (Timer)
GetQuote = strData(Rnd(1) * UBound(strData))
End Function
Re: Grabbing 5 Random Words from TXT File
Depends how your words are stored in the textfile; one word per line? space delimited? CSV?
Re: Grabbing 5 Random Words from TXT File
Nevermind I figured it out.