Print# Statement | Leading zeroes

W

ww

Hello

I am using the Print Statement to create a comma separated, quotes
file.

One of the data is a value with a leading zero "0234".

I have tracked its "print" to the OpenFile and it appears to print and
exist as "0234" until the Close# Command. Debug.Print shows the datum
to remain "0234" until the Close command which automatically converts
it to "0". >:-/

I am looking for ways to Print "0233" without it being interpreted as
a number. i have included a portion of the code below which has been
modified from the Knowledge Base solution for CommaQuotes files:

For RowCount = 1 To UBound(TheArray, 1)

' Loop for each column in selection.
For ColumnCount = 1 To UBound(TheArray, 2)
sVal = Format(TheArray(RowCount, ColumnCount), "")
' Write current cell's text to file with quotation
marks.
Print #FileNum, """" & sVal & """";

' Check if cell is in last column.
If ColumnCount = UBound(TheArray, 2) Then
' If so, then write a blank line.
Print #FileNum,
Else
' Otherwise, write a comma.
Print #FileNum, ",";
End If
' Start next iteration of ColumnCount loop.
Next ColumnCount
' Start next iteration of RowCount loop.
Next RowCount

' Close destination file.
Close #FileNum
End Sub

Thanks in advance.

W
 
T

Tom Ogilvy

The place to look is in the file itself. In the file is it written as
,"0234",
Sub Tester2()

Open "C:\Data\AAtext.Txt" For Output As #1
sVal = "0123"
Print #1, """" & sVal & """"
sVal = "0223"
Print #1, """" & sVal & """"
sVal = "0333"
Print #1, """" & sVal & """"
Close #1

End Sub

produced:

"0123"
"0223"
"0333"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top