I am having trouble getting my code to work properly. I am opening 2 seperate files, skipping through the header info, and copying the columns of data into named variables. Then, I am printing the data to a file in the order of taking data from both files, and putting them into 1. I'm not sure where I am messing up, but it is not working properly. The code is as follows:
Now, it is sort of working, as far as, placing the data in the order in which I need it to be placed. But I am only getting 1 line of code and not multiple lines. Does anyone have some insight? Thanks in advance
Code:
Open "C:\Temp.dat" For Append As #1
Set fso = CreateObject("Scripting.FileSystemObject")
Set objstream = fso.opentextfile(tFile, 1, False, 0) 'open selected file to read from
'delete header
Dim i As Integer
i = 0
Do While i < 32 And Not objstream.AtEndOfStream
strLine = objstream.Readline
i = i + 1
Loop
Do While Not objstream.AtEndOfStream
strLine = TrimAll(objstream.Readline)
yourarray = Split(strLine, " ") 'use tab to create space
'read into variables
depth = Format(Trim(yourarray(0)), "0")
If Trim(yourarray(1)) = "0.0000" Then
fph = "0.0"
Else
fph = Format(Trim(yourarray(1)), "0.0")
End If
If Trim(yourarray(2)) = "0.0000" Then
mpf = "0.00"
Else
mpf = Format(Trim(yourarray(2)), "0.00")
End If
If Trim(yourarray(3)) = "0.0000" Then
slide = "0.0"
Else
slide = Format(Trim(yourarray(3)), "0.0")
End If
If Trim(yourarray(4)) = "0.0000" Then
pdc = "0.0"
Else
pdc = Format(Trim(yourarray(4)), "0.0")
End If
If Trim(yourarray(5)) = "0.0000" Then
tgas = "0"
Else
tgas = Format(Trim(yourarray(5)), "0")
End If
If Trim(yourarray(6)) = "0.0000" Then
c1 = "0"
Else
c1 = Format(Trim(yourarray(6)), "0")
End If
If Trim(yourarray(7)) = "0.0000" Then
c2 = "0"
Else
c2 = Format(Trim(yourarray(7)), "0")
End If
If Trim(yourarray(8)) = "0.0000" Then
c3 = "0"
Else
c3 = Format(Trim(yourarray(8)), "0")
End If
If Trim(yourarray(9)) = "0.0000" Then
c4i = "0"
Else
c4i = Format(Trim(yourarray(9)), "0")
End If
If Trim(yourarray(10)) = "0.0000" Then
c4n = "0"
Else
c4n = Format(Trim(yourarray(10)), "0")
End If
If Trim(yourarray(11)) = "0.0000" Then
mwin = "0"
Else
mwin = Format(Trim(yourarray(11)), "0.0")
End If
If Trim(yourarray(12)) = "0.0000" Then
mwout = "0"
Else
mwout = Format(Trim(yourarray(12)), "0.0")
End If
If Trim(yourarray(13)) = "0.0000" Then
mtmpin = "0"
Else
mtmpin = Format(Trim(yourarray(13)), "0")
End If
If Trim(yourarray(14)) = "0.0000" Then
mtmpout = "0"
Else
mtmpout = Format(Trim(yourarray(14)), "0")
End If
Loop
'read from LITH file
Set fso = CreateObject("Scripting.FileSystemObject")
Set objstream = fso.opentextfile(lithFile, 1, False, 0) 'open selected file to read from
'delete header
Dim c As Integer
c = 0
Do While c < 1 And Not objstream.AtEndOfStream
strLine = objstream.Readline
c = c + 1
Loop
Do While Not objstream.AtEndOfStream
strLine = Trim(objstream.Readline)
myarray = Split(strLine, vbTab) 'use tab to create space
'read into variables
lithdepth = Format(Trim(myarray(0)), "0")
shale = Format(Trim(myarray(1)), "0")
silt = Trim(myarray(2))
sand = Trim(myarray(3))
chalk = Trim(myarray(4))
lime = Trim(myarray(5))
dolo = Trim(myarray(6))
anhy = Trim(myarray(7))
coal = Trim(myarray(8))
chert = Trim(myarray(9))
nosamp = Trim(myarray(10))
Loop
'print data to file in specific order
Print #1, depth & vbTab & fph & vbTab & mpf & vbTab & slide & vbTab & pdc & vbTab & tgas _
& vbTab & c1 & vbTab & c2 & vbTab & c3 & vbTab & c4i & vbTab & c4n & vbTab & shale _
& vbTab & silt & vbTab & sand & vbTab & chalk & vbTab & lime & vbTab & dolo & vbTab & anhy _
& vbTab & coal & vbTab & chert & vbTab & nosamp _
& vbTab & mwin & vbTab & mwout & vbTab & mtmpin & vbTab & mtmpout
'close open files
Close #1
fso = objstream.Close
fso = objstream.Close
Comment