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!

Duplicating first 2 fields when parsing???? 1

Status
Not open for further replies.

awelch

Technical User
Apr 24, 2002
85
US
Hello All,

I am needing help getting an output file in the correct format. My input file(.txt) has 3 fields. The fields are delimited by tabs, but the 3rd field has ranges and numbers seperated by commas.

ie. (very small sample)

rm ##98S 1234,3456,5678
rm ##233 345-678,679

I need to print out a file like this

rm ##98S 1234
rm ##98S 3456
rm ##98S 5678
rm ##233 345-678
rm ##233 679

I am able to parse through and break on the commas, but am unsure how to reprint the first 2 fields??? Here is the code I am using and the results:
Code:
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(buff, ",", -1)
     For lngCount = 0 To UBound(myarray)
     
       Print #2, myarray(lngCount)
     Next
   Loop
   
'close records
   Close #2
   Close #1
   
'notify when process is complete
   MsgBox "Finished Processing Files", vbOKOnly
   
   
End Sub

results:

rm ##98S 1234
3456
5678
rm ##233 345-678
679

Any ideas out there?
Thanks in advance!
 
something similar to this should do the trick.

Do While Not EOF(1)
Line Input #1, buff
myarray = Split(mid(buff,10,100), ",", -1)
For lngCount = 0 To UBound(myarray)

Print #2, mid(buff,1,10) & myarray(lngCount)
Next
Loop


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Thanks fredericofonseca!

I tried your solution of adding the Mid, there is only one problem. The first field that is seperated by the comma is correct, but any additional have the first 2 characters from the first printed with it.

ie:
rm ##98S 1234
rm ##98S 123456
rm ##98S 125678
rm ##233 345-678
rm ##233 34679


 
Disregard my last message. Got it working.


Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top