|
-
Apr 13th, 2005, 04:14 PM
#1
New Member
Re: txt file size?
 Originally Posted by dglienna
VB Code:
Option Explicit
Private Sub Form_Load()
Dim ff As Integer
Dim strBuff As String
Dim str() as string
ff = FreeFile
Open "c:\text.txt" For Input As #ff
strBuff = Input(LOF(ff), ff)
Close #ff
str() = split(strbuff, vbcrlf)
msgbox "There are " & ubound(str) -1 & " sentences in the file"
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
-
Apr 13th, 2005, 04:19 PM
#2
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?
-
Apr 13th, 2005, 05:04 PM
#3
New Member
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.
-
Apr 13th, 2005, 05:24 PM
#4
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.
-
Apr 13th, 2005, 05:48 PM
#5
New Member
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?
-
Apr 13th, 2005, 05:54 PM
#6
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.
-
Apr 13th, 2005, 06:22 PM
#7
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|