I am using VB6. I want to read a tab delimited file, and assign each column value into a variable. If the variable is "-999.25", I want to make it a "0". I then want to reassemble the values, and write them to a temp text file. Starting with line 64, I have about 28 columns and x number of rows. Ex: 1000<tab>23.3<t ab>-999.25<tab> etc. The value of -999.25 can be in any column. I need to replace it before it is stored in the variable. I need to rearrange the columns and write to the temp file.
Do you perhaps, as an expert, have a better way of achieving this? I'm still not sure how to change the -999.25 value to a 0 value when writing file. This is some of the code I have that I am working with, but it's not fully functional right now. Can you help me? Thanks for your time
Code:
Sub Perform()
Dim depth, fph, mpf, pdc, slide as String
Open "C:\Temp.dat" For Output As #1 'write to this file
Set fso = CreateObject("Scripting.FileSystemObject")
Set ObjStream = fso.opentextfile("C:\5inchto1inch.las", 1, False, 0)
'delete header
Dim i As Integer
i = 0
Do While i < 64 And Not ObjStream.AtEndOfStream
strLine = ObjStream.Readline
i = i + 1
Loop
Do While Not ObjStream.AtEndOfStream
strLine = TrimAll(ObjStream.Readline)
YourArray = Split(strLine, vbTab) '***use the tab key to create space
depth = Trim(YourArray(0))
fph = Trim(YourArray(1))
mpf = Trim(YourArray(2))
pdc = Trim(YourArray(3))
slide = Trim(YourArray(4))
'rearrange and write to temp file
Print #1, mpf & vbTab & pdc & vbTab & depth & vbTab & fph
Loop
Close #1
End Sub
Function TrimAll(Str)
'***remove all non ASCI chrs and reduce internal whitespace to single
Dim i, strTemp, strOut, strCh
strTemp = Str
For i = 1 To Len(strTemp)
strCh = Mid(strTemp, i, 1) '***look at each character in turn
'***if the chr is a space and the previous added chr was a space ignore it
'***otherwise add it on
If Not (strCh = " " And Right(strOut, 1) = " ") Or strCh = "." Then
strOut = strOut & strCh
End If
Next
TrimAll = strOut
End Function
Comment