Results 1 to 17 of 17

Thread: Count Letters In a String

Hybrid View

  1. #1

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

    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?

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Count Letters In a String

    Quote Originally Posted by DroopyPawn View Post
    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

  3. #3

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

    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
  •  



Click Here to Expand Forum to Full Width