I would like some expert advice. I am writing in VB6. I am opening a tab delimited file, deleting the first 50 lines, and rewriting the file to a temp file. The temp file has about 20 columns with x number of lines. What I am trying to do, is open the tab delimited file, and read each column into a named variable, ex. depth<column1>m pf<column2>tg<c olumn3>,etc. I have written a function to take the variable from column2(mpf) & create another variable(fph) to insert back into the file, at column2. This would move everything from column2(mpf) on, up one column. The columns and variables are as follows:
depth(column1), mpf(column2),tg (column3),c1(co lumn4),etc. with the variables. I need to create the variable fph and insert it into column2, where the new file will read as follows:
depth(column1), fph(column2),mp f(column3),tg(c olumn4),c1(colu mn5),etc to the end of the line. The code I have is as follows:
Could you help shed some light on this, or refer me to someone who may? Thanks for your time.
depth(column1), mpf(column2),tg (column3),c1(co lumn4),etc. with the variables. I need to create the variable fph and insert it into column2, where the new file will read as follows:
depth(column1), fph(column2),mp f(column3),tg(c olumn4),c1(colu mn5),etc to the end of the line. The code I have is as follows:
Code:
Public tFile As String Public mpf As Double Public fSave As String Public 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) = " ") Then strOut = strOut & strCh End If Next TrimAll = strOut End Function Private Sub cmdConvert_Click() Dim Script As Object Dim ObjStream As Object Dim strLine As String Dim a As Integer 'check for .las file Set Script = CreateObject("Scripting.FileSystemObject") If Script.FileExists(tFile) Then a = True Set ObjStream = Script.opentextfile(tFile, 1, False, 0) Else: MsgBox "There is no LAS data in file. Please update with new LAS data.", vbInformation + vbOKOnly a = False Exit Sub End If If tFile > "" Then 'open file Set Script = CreateObject("Scripting.filesystemobject") Open tFile For Input As #1 'read from this file Open "C:DB_CUETemp.dat" For Output As #2 'write to this file 'delete header and print rest of data to temp file If a = True Then Dim i As Integer i = 0 Do While i < 50 And Not ObjStream.AtEndOfStream strLine = ObjStream.Readline i = i + 1 Loop Do While Not ObjStream.AtEndOfStream strLine = TrimAll(ObjStream.Readline) YourArray = Split(strLine, " ") '***use the tab key to create space between quotes.*** Print #2, strLine Loop End If Close #1 Close #2 'save file With CommonDialog1 .Filter = "All Files|*.las*|" .InitDir = "C:DB_CUE" .DialogTitle = "Save File As" .ShowSave End With fSave = CommonDialog1.FileName 'copy temp file FileCopy "C:DB_CUETemp.dat", fSave '& ".las" 'delete temp file once copied Kill "C:DB_CUETemp.dat" If MsgBox("File is complete. Would you like to view the file?", vbQuestion + vbYesNo, "LAS iGenerator") = vbYes Then Shell ("Explorer.exe tFile"), vbNormalFocus ' Unload Me End If Else: If MsgBox("You must select a file to convert before you can continue.", vbExclamation + vbOKOnly) = vbOK Then Exit Sub End If End If End Sub
Comment