Results 1 to 6 of 6

Thread: Load Word List From Resource Text File

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Load Word List From Resource Text File

    I've added a resource fill with a list of words, one word on each line, to my project. I can't figure out how to load the list of words into my array in the Form_Load event.

    I've been loading the words from a text file on the hard drive but I've never used a resource file in VB6.

    Anyone?

  2. #2
    Junior Member wysiwyg327's Avatar
    Join Date
    May 2009
    Location
    App.Path
    Posts
    19

    Re: Load Word List From Resource Text File

    'hope this will help

    Sub LoadWords()
    Dim strtxt, Linestr As String
    Dim ArraySource() As String
    Dim ctr As Long

    'preserve array length
    ReDim Preserve ArraySource(0 To 10)

    'set the text source
    strtxt = App.Path & "\" & "textsource.txt"

    'set counter to 0
    ctr = 0

    'open text file
    Open strtxt For Input As #1

    Do While Not EOF(1)
    Line Input #1, Linestr

    'if greater than the ubound preserve array
    If ctr > UBound(ArraySource) Then ReDim Preserve ArraySource(0 To ctr + 10)

    'store each line to array
    ArraySource(ctr) = Trim(Linestr)
    ctr = ctr + 1
    Loop

    'remove excess array
    ReDim Preserve ArraySource(0 To ctr - 1)

    Close #1

    End Sub
    Last edited by wysiwyg327; May 13th, 2009 at 01:03 AM.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Load Word List From Resource Text File

    ¡Freakin' excellent!. Thanks.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Load Word List From Resource Text File

    On secnd thought, this doesn't work. It only looks for the file in the program's directory and tries to load the file from the hard dive. I can already do that.

    What I want is to include the text file in the .RES file that gets compiled into the .exe file. That way, nobody can edit the text file - possibly causing problems with my code.

    So the question remains, how do I load a text file into an array if that text file is compiled into the source code as a resource?

  5. #5
    Junior Member wysiwyg327's Avatar
    Join Date
    May 2009
    Location
    App.Path
    Posts
    19

    Re: Load Word List From Resource Text File

    'try to store this on a string variable or rich textbox then follow the post #2
    'generated from LoadRes Editor

    Code:
    var=StrConv(LoadResData(101, "CUSTOM"), vbUnicode)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Load Word List From Resource Text File

    The StrConv(....vbUnicode) fixed the "???" problem but now I think I'm stuck on the 32k limit of resource files. Some of my text files are nearly 3mb in size. Is there any way to include them as a resource or will I have to copy the text files with the .exe?

    Any other ideas? Maybe include the text files in a .dll or a custom control?

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