Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

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
0
markhilbert
Asked:
markhilbert
  • 2
2 Solutions
 
bruintjeCommented:
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
0
 
ptan218Commented:
Try this:

a=1
b=2.5
c=37

Open file.txt For Output As #1
Print #1, "Name"
Print #1, a & " " & b & " " & c
Close #1
0
 
bruintjeCommented:
rereading the question you can also try

Sub t()
a = 1
b = 2.5
c = 37

Open "c:\file.txt" For Output As #1
Print #1, "Name"
Print #1, Trim(a) & Chr(32); Trim(b) & Chr(32); Trim(c) & Chr(32)
Close #1

End Sub
0
 
markhilbertAuthor Commented:
Thanks to both of you, both solutions worked perfectly.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now