Link to home
Start Free TrialLog in
Avatar of markhilbert
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
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hello markhilbert,

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
SOLUTION
Avatar of ptan218
ptan218

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of markhilbert
markhilbert

ASKER

Thanks to both of you, both solutions worked perfectly.