ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reading from a dat file (https://www.excelbanter.com/excel-programming/440870-reading-dat-file.html)

Mike

Reading from a dat file
 
Could someon help me try to read a dat file with lines of text of this
format. If you paste this into a text file it show you what im dealing with.
Im not sure how to look for chr(166) and read whats between the chr

Any help would be great!!

0\ <Unknown PLU: \ ¦1¦726224¦QUORUM NIC
TORO¦999.99¦22.92¦1¦¦0¦0.00¦¦<Unknown PLU: ¦999.99¦22.92¦0.00¦0.00¦¦
101\ ASHTRAY CERAMIC ASST \
808178020826¦44¦72031¦Ashtray-Assorted
Ceramic¦2.30¦6.90¦1¦¦101¦50.00¦808178020826 ¦ASHTRAY CERAMIC ASST
¦2.30¦6.90¦4.59¦4.59¦¦
104\ JOB 1.5 PAPERS 24PK BOX\ 079083157246¦1¦028381¦JOB 1.5
CIGT. PAPERS¦26.27¦25.22¦1¦¦104¦25.00¦07908315724 6¦JOB 1.5 PAPERS 24PK
BOX¦26.27¦25.22¦35.05¦35.05¦¦
104\ TOP ROLLING PAPER 24 BOX\ 077170510011¦1¦029926¦TOP CIGT
PAPERS¦15.74¦14.69¦1¦¦104¦25.00¦07717051001 1¦TOP ROLLING PAPER 24
BOX¦15.74¦14.69¦20.99¦20.99¦¦

Jacob Skaria

Reading from a dat file
 
Mike, check out the below code..I have put some remarks along with the code

Sub Macro()

Dim intFile As Integer, strData As String, arrData As Variant

intFile = FreeFile

'Open file for reading
Open "d:\file1.dat" For Input As #intFile

'Loop until End of File
Do While Not EOF(intFile)

'Read one line
Line Input #intFile, strData

'Split the contents by Chr(166)
arrData = Split(strData, Chr(166))

'To retrive first field arrData(0)
'The below retrives field 3 726224 from the 1st line
MsgBox arrData(2)

Loop
Close #intFile


End Sub

--
Jacob


"Mike" wrote:

Could someon help me try to read a dat file with lines of text of this
format. If you paste this into a text file it show you what im dealing with.
Im not sure how to look for chr(166) and read whats between the chr

Any help would be great!!

0\ <Unknown PLU: \ ¦1¦726224¦QUORUM NIC
TORO¦999.99¦22.92¦1¦¦0¦0.00¦¦<Unknown PLU: ¦999.99¦22.92¦0.00¦0.00¦¦
101\ ASHTRAY CERAMIC ASST \
808178020826¦44¦72031¦Ashtray-Assorted
Ceramic¦2.30¦6.90¦1¦¦101¦50.00¦808178020826 ¦ASHTRAY CERAMIC ASST
¦2.30¦6.90¦4.59¦4.59¦¦
104\ JOB 1.5 PAPERS 24PK BOX\ 079083157246¦1¦028381¦JOB 1.5
CIGT. PAPERS¦26.27¦25.22¦1¦¦104¦25.00¦07908315724 6¦JOB 1.5 PAPERS 24PK
BOX¦26.27¦25.22¦35.05¦35.05¦¦
104\ TOP ROLLING PAPER 24 BOX\ 077170510011¦1¦029926¦TOP CIGT
PAPERS¦15.74¦14.69¦1¦¦104¦25.00¦07717051001 1¦TOP ROLLING PAPER 24
BOX¦15.74¦14.69¦20.99¦20.99¦¦


Mike

Reading from a dat file
 
Thanks Jacob I can work it out from there.

"Jacob Skaria" wrote:

Mike, check out the below code..I have put some remarks along with the code

Sub Macro()

Dim intFile As Integer, strData As String, arrData As Variant

intFile = FreeFile

'Open file for reading
Open "d:\file1.dat" For Input As #intFile

'Loop until End of File
Do While Not EOF(intFile)

'Read one line
Line Input #intFile, strData

'Split the contents by Chr(166)
arrData = Split(strData, Chr(166))

'To retrive first field arrData(0)
'The below retrives field 3 726224 from the 1st line
MsgBox arrData(2)

Loop
Close #intFile


End Sub

--
Jacob


"Mike" wrote:

Could someon help me try to read a dat file with lines of text of this
format. If you paste this into a text file it show you what im dealing with.
Im not sure how to look for chr(166) and read whats between the chr

Any help would be great!!

0\ <Unknown PLU: \ ¦1¦726224¦QUORUM NIC
TORO¦999.99¦22.92¦1¦¦0¦0.00¦¦<Unknown PLU: ¦999.99¦22.92¦0.00¦0.00¦¦
101\ ASHTRAY CERAMIC ASST \
808178020826¦44¦72031¦Ashtray-Assorted
Ceramic¦2.30¦6.90¦1¦¦101¦50.00¦808178020826 ¦ASHTRAY CERAMIC ASST
¦2.30¦6.90¦4.59¦4.59¦¦
104\ JOB 1.5 PAPERS 24PK BOX\ 079083157246¦1¦028381¦JOB 1.5
CIGT. PAPERS¦26.27¦25.22¦1¦¦104¦25.00¦07908315724 6¦JOB 1.5 PAPERS 24PK
BOX¦26.27¦25.22¦35.05¦35.05¦¦
104\ TOP ROLLING PAPER 24 BOX\ 077170510011¦1¦029926¦TOP CIGT
PAPERS¦15.74¦14.69¦1¦¦104¦25.00¦07717051001 1¦TOP ROLLING PAPER 24
BOX¦15.74¦14.69¦20.99¦20.99¦¦



All times are GMT +1. The time now is 07:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com