Results 1 to 19 of 19

Thread: txt file size?

Hybrid View

  1. #1
    New Member
    Join Date
    Apr 2005
    Posts
    9

    Re: txt file size?

    Quote Originally Posted by dglienna
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim ff As Integer
    5.   Dim strBuff As String
    6.   Dim str() as string
    7.   ff = FreeFile
    8.   Open "c:\text.txt" For Input As #ff
    9.     strBuff = Input(LOF(ff), ff)
    10.   Close #ff
    11.   str() = split(strbuff, vbcrlf)
    12.   msgbox "There are " & ubound(str) -1 & " sentences in the file"
    13. End Sub
    Hello! Can this code be used to search a text file for a string? When I tried it it worked but not on the whole file. I suppose the file is too big to load in a string. Is there a way around this without going into complex hardcore coding? Sorry but quite limited VB skills

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: txt file size?

    You can use pos = INSTR(strbuff,"Find this")
    if it is found, it will give the offset, if not it will return 0

    how big is your file? I've never had a problem with the size of a string.

    how many lines does it report?

  3. #3
    New Member
    Join Date
    Apr 2005
    Posts
    9

    Re: txt file size?

    6870 lines, a word on each line. I'm trying to search for complete words only not for string within the string (if you know what i mean ) Therefore when I load the file in a string I have to separate the words.
    Something like:
    Line Input #ff, strMystr
    strFull = strFull & Space(1) + strMystr

    Does that make it too big for a string? When I loaded it without spaces it searched the whole file but it's not what I needed.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: txt file size?

    No, I don't know that there is a limit, but it wouldn't be below 30000 characters

    You might want to load the words into a listbox, which you can then search for whole words, but it seems to me that if you search for a space before and a space after, you would get the whole word.

  5. #5
    New Member
    Join Date
    Apr 2005
    Posts
    9

    Re: txt file size?

    When i load the file into a string it looks like "hgawegudfisduhkljlsiueiyutsahsh..."
    So if I search for 'day' it will say 'Found' because I have the word 'birthday' somewhere in the file. And if I search for ' day ' it won't return any results.

    btw I know nothing about list boxes, should I start learning about them next?

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: txt file size?

    How do you expect to find words if you don't have words to start with. I thought you were splitting them. Show an example of what you have.

  7. #7
    New Member
    Join Date
    Apr 2005
    Posts
    9

    Re: txt file size?

    OK I mean when the string looks like "asdhkasjfjdkfdljgl..." it doesn't work and when I turn it into "dsf dgdfh asda..." it works fine but doesn't load the whole file. I used your code:
    Open "file.txt" For Input As #ff
    Do Until EOF(ff)
    Line Input #ff, strMystr
    strFull = strFull & Space(1) + strMystr
    Loop
    Close #ff
    iPos = InStr(strFull, strWord)
    If iPos > 0 Then
    MsgBox ("Found: ") & strWord
    Else
    MsgBox ("Not Found: ") & strWord
    End If

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