Reading text files

Reading text files

Anonymous
Not applicable
401 Views
5 Replies
Message 1 of 6

Reading text files

Anonymous
Not applicable
Hi,
I am new to VBA, can someone point me in the right direction. I want to read in a text file and create a schedule. Is it better to read the file into a record or read each line and get each word out of each line.
Is there a function like split that will read a text line and return each word to EOL

Any help would be great.
Thanks Chris
0 Likes
402 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Chris,



I'm not sure what you mean by a 'schedule' so my answers will be generic.



You can read either by line or field or character(s). You can only read by field if the line is comma-delimited. I've been using VB for years so tend to use what I know which is Open / Input # / Line Input #, however there is a more modern method using TextStream / Read / ReadLine / ReadAll.



Which method you choose depends on what you want to do with the information. If you need to process 'words' then you can indeed use the native Split function. If the contents of each word is irrelevant then I would use one of the 'chunkier' methods.



You'll find all these methods in the VBA Online Help.



Regards



Wayne Ivory

IT Analyst Programmer

Wespine Industries Pty Ltd
0 Likes
Message 3 of 6

Anonymous
Not applicable

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi,

I am new to VBA, can someone point me in the right direction. I want to
read in a text file and create a schedule. Is it better to read the file into
a record or read each line and get each word out of each line.
Is there a
function like split that will read a text line and return each word to EOL

Any help would be great.
Thanks Chris

0 Likes
Message 4 of 6

Anonymous
Not applicable
Is the split funtion available in all versions of VBA?

Tom Craft


wivory wrote:

> Chris,
>
> I'm not sure what you mean by a 'schedule' so my answers will be
> generic.
>
> You can read either by line or field or character(s). You can only
> read by field if the line is comma-delimited. I've been using VB for
> years so tend to use what I know which is Open / Input # / Line Input
> #, however there is a more modern method using TextStream / Read /
> ReadLine / ReadAll.
>
> Which method you choose depends on what you want to do with the
> information. If you need to process 'words' then you can indeed use
> the native Split function. If the contents of each word is irrelevant
> then I would use one of the 'chunkier' methods.
>
> You'll find all these methods in the VBA Online Help.
>
> Regards
>
> Wayne Ivory
> IT Analyst Programmer
> Wespine Industries Pty Ltd
0 Likes
Message 5 of 6

Anonymous
Not applicable
No, Split is only a version 6 function. However you can find a user-defined equivalent at this excellent site:


http://www.vb2themax.com/Item.asp?PageID=CodeBank&ID=194

Regards



Wayne
0 Likes
Message 6 of 6

Anonymous
Not applicable

Input #File, TextLineCol1, TextLineCol2, TextLineColn ...


Joe
--
0 Likes