markhilbert
asked on
Preceding Space when using Print command to write variables to a File.
Hi all,
I'm having a little trouble writing a text file with information from a vb program this is a sample of my code.
a=1
b=2.5
c=37
Open file.txt For Output As #1
Print #1, "Name"
Print #1, a; b; c
Close #1
I want the output file have a, b & c all on one line and seperated by spaces, not commas. Which this does, however it puts a space in the line before the variable "a" is printed, I can't get rid of the space. Name doesn't have a space before it when it is printed, so I really don't know why its insisting on putting the space there.
Output looks like this:
Name
1 2.5 7
Using the write command gets rid of the space however it places a comma between each variable.
Thanks.
Mark
I'm having a little trouble writing a text file with information from a vb program this is a sample of my code.
a=1
b=2.5
c=37
Open file.txt For Output As #1
Print #1, "Name"
Print #1, a; b; c
Close #1
I want the output file have a, b & c all on one line and seperated by spaces, not commas. Which this does, however it puts a space in the line before the variable "a" is printed, I can't get rid of the space. Name doesn't have a space before it when it is printed, so I really don't know why its insisting on putting the space there.
Output looks like this:
Name
1 2.5 7
Using the write command gets rid of the space however it places a comma between each variable.
Thanks.
Mark
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both of you, both solutions worked perfectly.
you can use a trim around the variables like
----------
Sub t()
a = 1
b = 2.5
c = 37
Open "c:\file.txt" For Output As #1
Print #1, "Name"
Print #1, Trim(a); Trim(b); Trim(c)
Close #1
End Sub
----------
hope this helps a bit
bruintje