|
-
May 13th, 2009, 11:53 PM
#1
Thread Starter
Hyperactive Member
Re: Count Letters In a String
Ok that makes sense now and also helps me with another problem....
If I add a "ListOfWords.txt" as a compiled resource and then get the "list of words" into a string, I could split the string into an array using vbCrLf as the delimiter, right?
-
May 14th, 2009, 06:06 PM
#2
Re: Count Letters In a String
 Originally Posted by DroopyPawn
If I add a "ListOfWords.txt" as a compiled resource and then get the "list of words" into a string, I could split the string into an array using vbCrLf as the delimiter, right?
Heres one way to load a text file into a string array.
Code:
Option Explicit
Private Sub Command1_Click()
Dim i As Long
Dim MyArray() As String
FileToArray "SomeFile.txt", MyArray
For i = 0 To UBound(MyArray)
' ignore blank lines
If Len(MyArray(i)) > 0 Then Debug.Print MyArray(i)
Next i
End Sub
Private Sub FileToArray(ByVal sPath As String, ByRef sArray() As String)
Dim ff As Integer
ff = FreeFile
On Error GoTo Fini
Open sPath For Input As #ff
sArray = Split(Input(LOF(ff), ff), vbCrLf)
Fini:
Close #ff
End Sub
-
May 14th, 2009, 06:31 PM
#3
Thread Starter
Hyperactive Member
Re: Count Letters In a String
What's the advantage to loading the file that way rather than reading each word in the file one at a time in a While Not EOF Loop?
Also, I don't want to read from a text file on the hard drive. I want to read from a file in the application's resources.
Last night, I got my code to recognize the compiled text file in the app, but when I put the text into a TextBox, all I got was question marks. It was nothing close to my expected list of words.
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
|