Importing portions of text files

This works

When the panic attack has passed, give this a shot. The caveats are:
1) More than three spaces in the text file signify a new field. There can be twenty spaces as long as there are more than three.
2)There must be no tilde (~) characters in the original text file.
3) The way the dates are output, the number of spaces between the parts of the date must not vary.
4)You don't float across the ether and clobber me if it doesn't work.
It writes a junk file called tmptest.txt on D: as well. Can always delete it after. I've included the test.txt file that works.
Good luck

Mike
 

Attachments

Whew...panic gone! Just don't ask!

Thanks so much for your time on this. There is a little bug though. This line:

Field2 = Mid(Field2, 1, FTilde) & TextDate(Mid(Field2, FTilde + 1, STilde - FTilde - 1)) _
& Mid(Field2, STilde, Len(Field2) - STilde)


is giving the error "Run time error '5'...Invalid procedure call or argument. What do I need to do to fix this? Thanks.
 
Stopped of for a beer on the way home last night. Hence a late response.
Code:
Field2 = Mid(Field2, 1, FTilde) & TextDate(Mid(Field2, FTilde + 1, STilde - FTilde - 1)) _
         & Mid(Field2, STilde, Len(Field2) - STilde)

All this line of code does is put together the the pieces of the data string. The error is not occuring in the TextDate function so that part is working.
The only other possibility is a bad argument in Mid.
Mid(string, start[, length]) - returns a substring of string starting at the start character position and length characters long.
The only one of these that could be causing this error is length. If it is zero or negative an error will occur.
It will be zero if there is a blank line. Or if no ~ character was found.
If no ~ was found, that means four spaces " " in a row were not found in the original data string.
Code:
Field2 = xg_ReplaceAllWith(Field2, "    ", "~") 'change more than 3 spaces to"~"
This is what you will probably have to play with. If there are actually tabs instead of four spaces in your data file then put chr(9) in place of " ".
Without having a piece of the actual data file there's not much more I can do.
 

Users who are viewing this thread

Back
Top Bottom