|
-
May 12th, 2009, 09:54 PM
#1
Thread Starter
Hyperactive Member
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?
-
May 13th, 2009, 12:59 AM
#2
Junior Member
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.
-
May 13th, 2009, 07:49 AM
#3
Thread Starter
Hyperactive Member
Re: Load Word List From Resource Text File
¡Freakin' excellent!. Thanks.
-
May 13th, 2009, 03:38 PM
#4
Thread Starter
Hyperactive Member
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?
-
May 15th, 2009, 01:09 AM
#5
Junior Member
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)
-
May 16th, 2009, 04:43 PM
#6
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|