Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

truncating numbers that start with zero

Status
Not open for further replies.

awelch

Technical User
Apr 24, 2002
85
US
I have this code to parse through a text file. The parsing works great, but I have one minor problem.... some of the fields may start with zeros, and the output is dropping them.... how do I get the output to print exactly what is in the input file????

Thanks in advance for your help!!!


Option Explicit

Private Sub cmdProcess_Click()
'declare variables
Dim lngCount As Long
Dim buff, tmpText, myarray() As String

'open files
Open "C:\inputfile.txt" For Input As #1
Open "C:\outputfile.txt" For Output As #2

'process file
Do While Not EOF(1)
Line Input #1, buff
myarray = Split(Mid(buff, 8, 100), ",", -1)
For lngCount = 0 To UBound(myarray)

Print #2, Mid(buff, 1, 8) & myarray(lngCount)
Next
Loop

'close records
Close #2
Close #1

'notify when process is complete
MsgBox "Finished Processing Files", vbOKOnly


End Sub


 
This will print exactly what is inputted
Line Input #1, buff
Print #2, buff

What is the purpose of your code in between the input and print?
 
> Print #2, Mid(buff, 1, 8) & myarray(lngCount)

I would look at the Format function. Without knowing what Mid(buff, 1, 8) is nor what myarray(lngCount) contains it's difficult to provide a specific example.

> Dim buff, tmpText, myarray() As String

Incidentally, you do realise that only myarray is being declared as String? buff and tmpText are being declared as Variant by default as there is no "As String". My apologies if you do. [smile]

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"Why does my program keep showing error messages every time something goes wrong?"
 
Just what I was about to say - declare your variables properly, and you might find the problems go away...

mmilan
 
Thanks for the responses.... I got it figured out just after posting, but lost connection...

Thanks again..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top