using the 'Print' statement in VB
-
I've got a string variable that goes through heavy string manipulation that may or may not leave the string with a 'carriage return - line feed' at the end. It is declared like this:
Dim buf as String Dim filenum as Integer
Now i'm trying to output this string into a file and this is JUST ONE of the ways i've tried:filenum = FreeFile Open "newfile.txt" For Output As filenum Print #filenum, buf Close filenum
Now here's my problem: No matter how i try this, after opening the file in an external editor I see that a 'carriage return - line feed' has been added to the end. I can't seem to avoid this and it's DRIVING ME CRAZY! When 'buf' has a final character of '.', then when I open the file in my editor and press <Ctrl>+<End>, I expect the cursor to fall to the right of the '.' not on the blank line below. And before you ask, the editor I'm using doesn't do anything extra like ensuring a blank last line (like the VB environment). I've tried various combinations of: opening the file in binary or text mode, opening for input or random, using the 'Print' or 'Put' function. Can anybody tell me how to output a string to a file WITHOUT adding a blank last line? thanks, nebbish Smart, Sexy, Sane. Pick two. -
I've got a string variable that goes through heavy string manipulation that may or may not leave the string with a 'carriage return - line feed' at the end. It is declared like this:
Dim buf as String Dim filenum as Integer
Now i'm trying to output this string into a file and this is JUST ONE of the ways i've tried:filenum = FreeFile Open "newfile.txt" For Output As filenum Print #filenum, buf Close filenum
Now here's my problem: No matter how i try this, after opening the file in an external editor I see that a 'carriage return - line feed' has been added to the end. I can't seem to avoid this and it's DRIVING ME CRAZY! When 'buf' has a final character of '.', then when I open the file in my editor and press <Ctrl>+<End>, I expect the cursor to fall to the right of the '.' not on the blank line below. And before you ask, the editor I'm using doesn't do anything extra like ensuring a blank last line (like the VB environment). I've tried various combinations of: opening the file in binary or text mode, opening for input or random, using the 'Print' or 'Put' function. Can anybody tell me how to output a string to a file WITHOUT adding a blank last line? thanks, nebbish Smart, Sexy, Sane. Pick two. -
Well thanks for the idea Pablo75, but the 'Write' statement added a double quote at the beginning and again at the end of the file. Essentially the whole file was enclosed in one set of double-quotes. And by the way, for anybody else whose reading this thread as well, I've had success when opening the file in binary mode and using the 'Put' function EXCEPT when I am replacing an existing (text) file with a string that is shorter. In those cases, opening the file in binary does not reset the length of the file, so the file ends up being my new string followed by the old contents of the file that existed beyond the length of the new string. Can I open an existing file in binary and somehow reset the file length? discarding the old contents entirely? thanks, nebbish Smart, Sexy, Sane. Pick two.