Code Failure...

linuxman
01-11-2004, 08:48 PM
When I use the following code to remove comma's in a text file, I get a return record or carriage marker (little square between records). So when I try to import the text file into Access it craps out on the very last records because the field does not allow allow empty records.

My question is there any easy way to get the last little record separator out of the file. Some of the files have a million list of numbers in them.

Dim textfile As String

Open App.path & "\DNCImport\" & NewFileName For Input As #1
textfile = Input$(LOF(1), 1)
Close #1

textfile = Replace(textfile, ",", "")

Open App.path & "\DNCImport\" & NewFileName For Output As #2
Print #2, textfile
Close #2

That is the code I am using to strip the return marker, some how it is placing a little something after the last record and making it appear that it is a blank record. The code works great; EXCEPT for that one little problem.

Optikal
01-11-2004, 08:50 PM
Use Left$() function to remove however many characters from the end of the string that you desire.

linuxman
01-11-2004, 09:06 PM
Use Left$() function to remove however many characters from the end of the string that you desire.
Will this work on a file with a million 10-character numbers and be efficient?

linuxman
01-11-2004, 09:08 PM
Use Left$() function to remove however many characters from the end of the string that you desire.
Furthermore I am confused as to why the left$() when the last character is at the end (I am assuming is the right).

Optikal
01-11-2004, 09:14 PM
if the string is 100 chars, you want to output the left-most 99 chars, hence the Left$() function

and doing anything with a million-char string will be slow

linuxman
01-11-2004, 09:31 PM
if the string is 100 chars, you want to output the left-most 99 chars, hence the Left$() function

and doing anything with a million-char string will be slow
This is what I figure, I just have no idea why the original code in the first posting is leaving something past there. It doesn't make sense to me as there is nothing there to begin with, so why in the world does the code leave a blank space after the last actual record. I am now leaning toward opening the text file after converting it and stripping the last records which should work, again I think it will be slow. I wish I could find a better way to strip the commas out. I think I will look at a batch file. I found a great utility that works fine and extremely fast. However this is not the answer either. I need to get it into this particuar program. The program is freeware so I thought I would call them and see how much they would charge for the code to do this. It is very frustrating I have never spent a weekend working on something I thought was very simple.

Optikal
01-11-2004, 10:42 PM
The Print # statement automatically puts a vbCrLf on the end of the output, you can suppress this behaviour by adding a semi-colon like so:

Print #2, textfile;

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum