Board index » Visual Studio » How to read a Tab Delimited text file in to a Flexgrid without using .Clip Method
|
DaveKramer
|
|
DaveKramer
|
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 - |
| Rick
Registered User |
Wed Nov 30 03:03:50 CST 2005
Re:How to read a Tab Delimited text file in to a Flexgrid without using .Clip MethodQuoteHow to read a Tab Delimited text file in to Rick - |
| Cmaz
Registered User |
Wed Nov 30 06:11:36 CST 2005
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 - |
| Rick
Registered User |
Wed Nov 30 08:29:26 CST 2005
Re:How to read a Tab Delimited text file in to a Flexgrid without using .Clip MethodQuoteI need to Read Tab limited Txt file in other controls, QuoteI saw Your eg. in a previous post...its very good.. Quoteanother problem the flexgrid displays a special charecter 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. QuoteFurther i should be able to find the no of cols and rows in 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 - |
| Dave
Registered User |
Thu Dec 01 04:50:09 CST 2005
Re:How to read a Tab Delimited text file in to a Flexgrid without using .Clip MethodQuoteAs I 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. - |
