Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fixed width file

Status
Not open for further replies.

asmotritsky

Programmer
Sep 8, 2001
1
US
What is a fixed width text file, and how do I work with it in VB?
 
Refer to the 'Open (file) For Random' statement in VB. Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
asmotritsky -

It's a data file where each record and each field in the record is the same length as all the other records.
Example:
[tt]
122-3123Outboard Johnson 500cc 1499.99
122-2332Outboard Honda 600cc 1899.99
004-0002Bait Cricket 4oz 2.99
004-0002Bait Nightcrawler 6oz 4.99
[/tt]
Each field in the record is the same length, which results in each record being the same length.

You would use VB's standard file reading/writing calls to read these files. You would also need to know the length of each record, so that you can read it a record-at-a-time. Once you've read the record, you can use the mid$() function to divide it up into fields, and store them into a class.
[tt]
Option Explicit
Private m_StockNum as String
Private m_Category as String
Private m_Item as String
Private m_Capacity as String
Private m_Price as Currency

Public Property Let RecordAsString(ByVal RHS as String)
m_StockNum = Mid$(RHS, 1, 8)
m_Category = Mid$(RHS, 9, 17)
m_Item = Mid$(RHS, 26, 18)
m_Capacity = Mid$(RHS, 45, 6)
m_Price = CCur(Mid$(RHS, 52, 8))
End Property

Public Property Get StockNum() as String
StockNum = m_StockNum
End Property
Public Property Get Category() as String
Category= m_Category
End Property
Public Property Get Item() as String
Item= m_Item
End Property
Public Property Get Capacity () as String
Capacity = m_Capacity
End Property
Public Property Get Price() as Currency
Price = m_Price
End Property
[/tt]

Hope this helps.
Chip H.
 
asmotritsky -

Darn! The Tek-Tips forum software is wrapping my sample file. Please assume that the sample fishing item file starts each line with an 8-place stocknumber, and ends with the item's price.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top