Results 1 to 3 of 3

Thread: [RESOLVED] Grabbing 5 Random Words from TXT File

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    395

    Resolved [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:
    1. Public Function GetQuote(QuoteFile As String) As String
    2.  
    3. Dim strData() As String, strWholeFile As String
    4. Dim intFileNum As Integer
    5.  
    6. intFileNum = FreeFile
    7.  
    8. 'Allocate buffer and read in complete file
    9. strWholeFile = Space(FileLen(QuoteFile))
    10. Open QuoteFile For Binary As #intFileNum
    11. Get #intFileNum, , strWholeFile
    12. Close intFileNum
    13.  
    14. 'Remove carriage returns
    15. strWholeFile = Replace(strWholeFile, vbCr, "")
    16.  
    17. 'Convert into Array
    18. strData = Split(strWholeFile, vbLf)
    19.  
    20. 'Randomly select element from array
    21. Randomize (Timer)
    22.  
    23. GetQuote = strData(Rnd(1) * UBound(strData))
    24.  
    25. End Function

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Grabbing 5 Random Words from TXT File

    Depends how your words are stored in the textfile; one word per line? space delimited? CSV?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    395

    Re: Grabbing 5 Random Words from TXT File

    Nevermind I figured it out.
    8 gigs/ram (hey why not)
    300 gig HD x2
    Windows XP 64

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