f



Reading many fields/text/data from a single text file

I tried it with RTF, I am able to read the entire content. Same goes with
the TXT file. But is VB able to allow you to read various data from a
single text file?

0
2/25/2005 4:14:31 AM
comp.lang.basic.visual.misc 10153 articles. 0 followers. Post Follow

5 Replies
1061 Views

Similar Articles

[PageSpeed] 40

> I tried it with RTF, I am able to read the entire content.
> Same goes with the TXT file. But is VB able to allow
> you to read various data from a single text file?

The only thing your post has told us is that you are having some kind of
problem; but not the details of what that problem is. How big is the
file you are trying to read? What is happening when you can't read the
entire contents (for example, are you getting an error message or
something else)? How were you trying to read it in? What is the
structure of the file (just saying "many fields/text/data" tells us
nothing)? We would like to help, maybe even suggest some code to try,
but you will have to give us more details as to what you have, what you
want to do with it, what you have tried, and what is happening when you
tried it. Details... we need details.

Rick - MVP

0
2/25/2005 4:32:04 AM
Sorry, hehe!

What I meant to say was the file contain approximately 50 lines worth of
text.

What I'm trying to do is to read the value from the file. But reading
different values.

I have not tried it yet but if this is impossible then I will find some
other alternatives. So I just needed to find out if this is possible.

0
2/25/2005 4:40:47 AM
> Sorry, hehe!
>
> What I meant to say was the file contain approximately 50 lines worth
of
> text.
>
> What I'm trying to do is to read the value from the file. But reading
> different values.
>
> I have not tried it yet but if this is impossible then I will find
some
> other alternatives. So I just needed to find out if this is possible.

50 lines of text is not that much, you should be able to do that with no
problem. One possible problem could be your text file is not made up of
pure text. If that were the case, you might be running into an
End-Of-File character embedded inside the file. This can be worked
around if necessary. However, you still have not described what your
file looks like. Is it structured in some way... Fixed column widths?
Are the fields delimited in some way? If the file is really pure text,
why don't you copy the 50 lines and paste them into your response so we
can see what you have to work with. And remember to tell us what part of
the file you are trying to extract.

Rick - MVP

0
2/25/2005 5:28:35 AM
"RayKnight" <rayknightro@yahoo.com> wrote in message 
news:346bd6353343c0871fb851984f725829@localhost.talkaboutprogramming.com...

> What I meant to say was the file contain approximately 50 lines
> worth of text. What I'm trying to do is to read the value from the
> file. But reading different values.

It is possible to do just about anything at all with a file. But I'm not 
sure exactly what it is you want to do. Can you tell us exactly what this 
file contains, and what code you are currently using to read it? Post some 
of your current code.

The VB Input # statement will read data from a file up to the next delimiter 
(usually a comma or a carriage return / line feed) and place it into one (or 
more) variables. Alternatively, the VB Line Input# statement will read an 
entire line from a file (up to the next carriage return / line feed) and 
will assign that line to a VB string variable.

Much depends on the exact layout of the file. If it is a standard text file 
containing standard text and you want to read the text one "line" at a time 
then use the Line Input # function. Alternatively, you can read the entire 
text file into a single String variable and then use the VB Split function 
to break that up into its individual lines and assign them to a String 
array.

Here is an example of the latter method, which shows how to get the entrie 
file into one String and also how to Split that string up into individual 
lines in a String array. This is not necessarily the best way of 
accomplishing the task, but it does show you how to do both things that your 
might possibly want to do.

Mike

Private Sub Command1_Click()
Dim s1 As String, s2() As String
Open "c:\module.txt" For Binary As 1
s1 = Space$(LOF(1))
Get 1, 1, s1
Close 1
s2() = Split(s1, vbCrLf)
Print Len(s1)
Print LBound(s2) ' number of first array element
Print UBound(s2) ' number of last array element
End Sub



0
mike5607 (1952)
2/25/2005 5:07:59 PM
Thanks, and sorry for the late reply. My friend wanted this, and he didn't
even give me the complete details. So I wasn't of much help to you guys
and him. *I hate being the middleman*

Thanks! I'll get him to try it.

0
3/1/2005 5:06:24 PM
Reply: