editing .txt with VBA - importing format question

R

RC51WV

Is it possible to edit a .txt file with VBA?

I have .txt files that will need to be imported when selected by a user.
this is what the information looks like

NAMEOFJOB=MYJOBIS
cmd=1234567;TYP;12345;1.0;1;1234567
01:\\Imagepath\imagename1.tif
cmd=1234567;TYP;12345;1.0;1;1234567
02:\\Imagepath\imagename2.tif
cmd=1234567;TYP;12345;1.1;2;1234567
01:\\Imagepath\imagename1.tif
cmd=1234567;TYP;12345;1.1;2;1234567
02:\\Imagepath\imagename2.tif

The fields straight across the table are:

OracleIDNumb
Doc Type
Image Frame
Image Number
Capt Img Number
Doc ID
Image Path

I need to get the lines starting with cmd to be entered into the first 6
fields with the ; being the delimiter and the 01:\\imagepath etc... on the
second line to be entered into the 7th field, Image Paht. How do I go about
working on this?

-Thanks
 
J

John Nurick

It's not so much a matter of editing a text file as reading it and
writing a new one that contains your changes and can be imported in the
usual way

In this case you need (it appears) to

1) dump the first "NAMEOFJOB" line
2) read the next two lines and concatenate them with a ; between
3) write the result to disk
4) loop back to (2) until you reach the end of the file.

In VBA one can do it along these lines (air code!):

Dim strSource As String
Dim strDestination As String
Dim lngSource As Long
Dim lngDestination As Long
Dim str1 As String
Dim str2 As String

'filespecs (in real life, user specifies source file)
strSource = "D:\Folder\Original.txt"
strDestination = "D:\Temp\Import.txt"

'open files
lngSource = FreeFile()
Open strSource For Input As #lngSource
lngDestination = FreeFile()
Open strDestination for Output as #lngDestination

'Dump first line
Line Input #lngSource, str1

'Loop through remainder
Do Until EOF(lngSource)
Line Input #lngSource, str1
Line Input #lngSource, str2
Print #lngDestination, str1 & ";" & str2
Loop

'Tidy up
Close #lngSource
Close #lngDestination
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top