Board index » Visual Studio » How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method

How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method

Visual Studio195
How to read a Tab Delimited text file in to a Flexgrid without using

.Clip Method


-
 

Re:How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method

Quote
How to read a Tab Delimited text file in to

a Flexgrid without using .Clip Method



Why would you want to?



Rick





-

Re:How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method

I need to Read Tab limited Txt file in other controls, on a form,

convert to PDF .... etc etc



I saw Your eg. in a previous post...its very good..



another problem the flexgrid displays a special charecter in the first

col if .Clip method is used.

Further i should be able to find the no of cols and rows in the Txt

file . to re create the file to any suitable control .



Thank You



-

Re:How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method

Quote
I need to Read Tab limited Txt file in other controls,

on a form, convert to PDF .... etc etc



Fair enough.



Quote
I saw Your eg. in a previous post...its very good..



Thank you.



Quote
another problem the flexgrid displays a special charecter

in the first col if .Clip method is used.



This does not (and has not) ever happen to me and should not happen to

your either. The special character is probably in your file. If so,

you will have to account for that in the code below. If you want to

pursue this (the Clip method that is), post back a new message to this

newsgroup so we can examine it further. I would be interested in

knowing what the special character is (strip it off of the text

returned by the Clip method) and MsgBox or Debug.Print its ASCII value

(use the Asc function) out and include that in your posting.



Quote
Further i should be able to find the no of cols and rows in

the Txt file . to re create the file to any suitable control .



The following method should get you going in order to do this...



You can use the following code to read the entire file into memory all

at once, split the file down into individual records (lines) and then

process each record one at a time, splitting the text using the built

in VB constant vbTab as the delimiter, and do whatever you need to

with these fields of data.



Dim X As Long

Dim FileNum As Long

Dim Delimiter As String

Dim TotalFile As String

Dim Fields() As String

Dim Records() As String

FileNum = FreeFile

' Reads the whole file into memory all at once

Open "c:\SomeDircectory\YourFile.txt" For Binary As #FileNum

TotalFile = Space(LOF(FileNum))

Get #FileNum, , TotalFile

Close #FileNum

' Put each line of the file into the Records array

Records = Split(TotalFile, vbNewLine)

' Examine each record one at a time and process its fields or data

For X = 0 To UBound(Records)

' Put each item delimited by the Tab character into the Fields

array

Fields = Split(Records(X), vbTab)

'

' You now have access to the individual fields

' within the Record #X, via the array elements

' of the Fields array, so do whatever you need

' to them here.

'

Next



In case you are unaware of it, vbNewLine (used to Split each record

into the Fields array above) is a built-in constant in VB (just like

vbTab is) which is made up of the two characters that delimit a new

line in Windows (a Carriage Return character followed by a Line Feed

character). VB has a second constant that also contains these

characters... vbCrLf.... you may use this instead if you wish. As I

recall, the Clip method uses a single Carriage Return character as its

record (Row) separator. If your file is built this way (using a single

Carriage Return instead of Window's normal Carriage Return followed by

a Line Feed for separating the lines in your file), then you can use a

different built-in constant, vbCr, to Split each record into the

Fields array above.



Rick





-

Re:How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method

Quote
As I

recall, the Clip method uses a single Carriage Return character as its

record (Row) separator. If your file is built this way (using a single

Carriage Return instead of Window's normal Carriage Return followed by

a Line Feed for separating the lines in your file), then you can use a

different built-in constant, vbCr, to Split each record into the

Fields array above.



Rick



What I do is a replace vbCrLf with VbCr then treat the file as CR line

delimited, that way you can process files of either sort without having to

worry about it or even know how each file is formatted. (does add a bit of

processing time for large files, buy hey, what doesn't?).



eg: Records = Split(Replace(TotalFile, vbCrLf, VbCr), vbCr)



Regards

Dave O.





-