Writing 4 digit Zip Code to .dat file

J

Joe Mac

All...

I looking for some assistance in creating a ".dat" output file based upon
input from an Excel spreadsheet...

All works fine with the exception of Zip Code fields beginning with a "0"...
I've tried a couple of ways to establish the output first evaluating the
length of the Excel cell containing the Zip Code and based on a length of 4
to create a variable with the leading "0" & the 4 digits from the cell...
the output file is only containing the 4 digit Excel values... Any
assistance is greatly appreciated...

Code is attached

Open OutputFile For Output Access Write As #1 Len = 735

For n = 2 To InputRowCount
If Len(InputRange.Cells(n, 7)) = 4 Then
' ZipCode = Format(InputRange.Cells(n, 7), "00000")
ZipCode = CStr("0" & InputRange.Cells(n, 7))
Else
ZipCode = Trim(InputRange.Cells(n, 7))
End If
If IsEmpty(InputRange.Cells(n, 1)) Then
n = InputRowCount
Else
Print #1, (InputRange.Cells(n, 2)); Spc(307 + (15 -
(Len(InputRange.Cells(n, 2))))); _
Format((InputRange.Cells(n, 1)), "mm/dd/yyyy hh:mm:ss");
Spc(39 + (28 - (Len(InputRange.Cells(n, 1))))); _
(InputRange.Cells(n, 3)); Spc(51 -
(Len(InputRange.Cells(n, 3)))); _
(InputRange.Cells(n, 4)); Spc(31 + (31 -
(Len(InputRange.Cells(n, 4))))); _
(InputRange.Cells(n, 5)); Spc(31 -
(Len(InputRange.Cells(n, 5)))); _
(InputRange.Cells(n, 6)); Spc(8 -
(Len(InputRange.Cells(n, 6)))); _
ZipCode; Spc(11 - Len(ZipCode)); Spc(172); Chr(10)
End If
Next n
Print #1, ("USACRDA" & Format(Date, "mmddyyyy") &
Format(InputRowCount - 1, "000000000")); Spc(711);
End With
 
J

Joe Mac

I was able to resolve the condition by changing the Zipcode variable definition

Joe
 

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