Prev: ignore
Next: Revise my code
From: RB Smissaert on
Trying to write a string to file with the Write statement, but without
getting a trailing linebreak.

Sub test()

Dim strFile As String
Dim hFile As Long

strFile = "C:\testing.txt"

hFile = FreeFile

Open strFile For Output As hFile

Write #hFile, "test"

Close #hFile

End Sub

This will write the string "test", but it will have trailing linebreak.
How do I avoid this linebreak?


I can do this:

Print #hFile, Chr(34) & "test" & Chr(34);

But I wonder if I can do the same with the Write statement.


RBS

From: Henning on
Will Write #hFile, "test"; do

/Henning

"RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> skrev i meddelandet
news:uHTHzHP5IHA.4560(a)TK2MSFTNGP04.phx.gbl...
> Trying to write a string to file with the Write statement, but without
> getting a trailing linebreak.
>
> Sub test()
>
> Dim strFile As String
> Dim hFile As Long
>
> strFile = "C:\testing.txt"
>
> hFile = FreeFile
>
> Open strFile For Output As hFile
>
> Write #hFile, "test"
>
> Close #hFile
>
> End Sub
>
> This will write the string "test", but it will have trailing linebreak.
> How do I avoid this linebreak?
>
>
> I can do this:
>
> Print #hFile, Chr(34) & "test" & Chr(34);
>
> But I wonder if I can do the same with the Write statement.
>
>
> RBS
>


From: RB Smissaert on
No that appends a comma.
I use this as well as I am using this mainly to write
a 2-D variant array to text as a comma and linebreak separated text file.

RBS


"Henning" <computer_hero(a)coldmail.com> wrote in message
news:487a1711$0$12246$57c3e1d3(a)news3.bahnhof.se...
> Will Write #hFile, "test"; do
>
> /Henning
>
> "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> skrev i meddelandet
> news:uHTHzHP5IHA.4560(a)TK2MSFTNGP04.phx.gbl...
>> Trying to write a string to file with the Write statement, but without
>> getting a trailing linebreak.
>>
>> Sub test()
>>
>> Dim strFile As String
>> Dim hFile As Long
>>
>> strFile = "C:\testing.txt"
>>
>> hFile = FreeFile
>>
>> Open strFile For Output As hFile
>>
>> Write #hFile, "test"
>>
>> Close #hFile
>>
>> End Sub
>>
>> This will write the string "test", but it will have trailing linebreak.
>> How do I avoid this linebreak?
>>
>>
>> I can do this:
>>
>> Print #hFile, Chr(34) & "test" & Chr(34);
>>
>> But I wonder if I can do the same with the Write statement.
>>
>>
>> RBS
>>
>
>

From: Henning on
Right!

Then if you need " written there is just:
change Write to Print #hFile, Chr$(34) & "test" & Chr$(34);

or

Dim strFile As String
Dim hFile As Long
Dim s As String

strFile = "C:\testing.txt"

s = Chr$(34) & "test" & Chr$(34)

hFile = FreeFile

Open strFile For Binary As hFile Len = Len(s)

Put #hFile, , s

Close #hFile

/Henning


"RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> skrev i meddelandet
news:urId0nP5IHA.5012(a)TK2MSFTNGP02.phx.gbl...
> No that appends a comma.
> I use this as well as I am using this mainly to write
> a 2-D variant array to text as a comma and linebreak separated text file.
>
> RBS
>
>
> "Henning" <computer_hero(a)coldmail.com> wrote in message
> news:487a1711$0$12246$57c3e1d3(a)news3.bahnhof.se...
>> Will Write #hFile, "test"; do
>>
>> /Henning
>>
>> "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> skrev i meddelandet
>> news:uHTHzHP5IHA.4560(a)TK2MSFTNGP04.phx.gbl...
>>> Trying to write a string to file with the Write statement, but without
>>> getting a trailing linebreak.
>>>
>>> Sub test()
>>>
>>> Dim strFile As String
>>> Dim hFile As Long
>>>
>>> strFile = "C:\testing.txt"
>>>
>>> hFile = FreeFile
>>>
>>> Open strFile For Output As hFile
>>>
>>> Write #hFile, "test"
>>>
>>> Close #hFile
>>>
>>> End Sub
>>>
>>> This will write the string "test", but it will have trailing linebreak.
>>> How do I avoid this linebreak?
>>>
>>>
>>> I can do this:
>>>
>>> Print #hFile, Chr(34) & "test" & Chr(34);
>>>
>>> But I wonder if I can do the same with the Write statement.
>>>
>>>
>>> RBS
>>>
>>
>>
>


From: MikeD on
Use the same syntax Henning suggested but use Print# instead of Write#. You
might also want to take a look at Help for these 2 statements to learn their
differences (BTW, Help *clearly* states that Write# "inserts a newline
character").

--
Mike
Microsoft MVP Visual Basic



"RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> wrote in message
news:urId0nP5IHA.5012(a)TK2MSFTNGP02.phx.gbl...
> No that appends a comma.
> I use this as well as I am using this mainly to write
> a 2-D variant array to text as a comma and linebreak separated text file.
>
> RBS
>
>
> "Henning" <computer_hero(a)coldmail.com> wrote in message
> news:487a1711$0$12246$57c3e1d3(a)news3.bahnhof.se...
>> Will Write #hFile, "test"; do
>>
>> /Henning
>>
>> "RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> skrev i meddelandet
>> news:uHTHzHP5IHA.4560(a)TK2MSFTNGP04.phx.gbl...
>>> Trying to write a string to file with the Write statement, but without
>>> getting a trailing linebreak.
>>>
>>> Sub test()
>>>
>>> Dim strFile As String
>>> Dim hFile As Long
>>>
>>> strFile = "C:\testing.txt"
>>>
>>> hFile = FreeFile
>>>
>>> Open strFile For Output As hFile
>>>
>>> Write #hFile, "test"
>>>
>>> Close #hFile
>>>
>>> End Sub
>>>
>>> This will write the string "test", but it will have trailing linebreak.
>>> How do I avoid this linebreak?
>>>
>>>
>>> I can do this:
>>>
>>> Print #hFile, Chr(34) & "test" & Chr(34);
>>>
>>> But I wonder if I can do the same with the Write statement.
>>>
>>>
>>> RBS
>>>
>>
>>
>


 |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9
Prev: ignore
Next: Revise my code