fixed length strings

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
I am trying to read/write and address value to a text file that is space delimited. I assume there is a good approach using fixed length strings but I haven't figured it out yet. What is the best way to write to the file that makes it easier to read. And as a result, how to read it?

Thank you
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Where do you want the spaces? Before the text or after?
You can open the text file in any app that supports text files such as Notepad or did you want a macro to read it back into Excel or what?
 
Upvote 0
If you do a File SaveAs and select the Formatted Test (Space delimited) (*.prn) option, it will save your file as a space delimited text file (which is usually pretty easy to read using NotePad or any other text editor).
 
Upvote 0
I'm actually writing the text file with something like this:

Print #1, object.address1 & " " & object.address2 & " " & object.city & " " & object.state & " " & object.zip

I was reading the file by getting the line of text and then using the split function. Problem is spaces in the address text. I temporarily changed the delimiter for this particular line to "$$" but I think there is a better way to do this.
 
Upvote 0
I would read it in using the Workbooks.OpenText Method (see VBA help file)

Why are you using space as the delimiter anyway?

If it's for readability you could use Chr(160) as your delimiter instead.
 
Upvote 0
Maybe I should have mentioned that the program has to be compatible with xl2000. Also, the file that I am writing the text for is used by another program that reads a space delimiter. That program somehow encapulates the field with quotations and reads a fixed length string. That was why my question was worded as such.

Thank you
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top