Results 1 to 7 of 7

Thread: write a new file?

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    write a new file?

    code below use to extract data from file(data.txt).now,i need to write the value strLatitude,strLongitude,strDepthto a new file and save it. How to write the code?

    VB Code:
    1. private Sub readFile()
    2. Dim blnStartReading1 As Boolean, blnStartReading2 As Boolean
    3. Dim strTestData As String
    4. Dim A As Integer
    5. Dim B As Integer
    6. Dim i As Integer
    7. Dim ii As Integer
    8. Dim strLatitude As String
    9. Dim strLongitude As String
    10. Dim strDepth As String
    11. ChDir App.Path
    12.  
    13. Open strfilename For Input As #2
    14.     blnStartReading1 = False: blnStartReading2 = False
    15.    
    16.     While Not EOF(2)
    17.         Line Input #2, strTestData
    18.         If strTestData = "STOP" Then blnStartReading2 = False
    19.        
    20.         If blnStartReading1 = True And blnStartReading2 = True Then
    21.             A = Len(strTestData)
    22.             For B = 1 To A
    23.                 If Mid(strTestData, B, 1) = " " Then
    24.                     strLongitude = Mid(strTestData, 1, B - 1)
    25.                     strLatitude = Mid(strTestData, B + 1, A)
    26.                     Exit For
    27.                 End If
    28.             Next B
    29.         MsgBox " " & [COLOR=Magenta]strLatitude[/COLOR] & " " & [COLOR=Magenta]strLongitude[/COLOR]  & " " & [COLOR=Magenta]strDepth[/COLOR] & ""
    30.        End If
    31.                      
    32.         If blnStartReading1 = True And blnStartReading2 = False Then
    33.             i = InStr(strTestData, "174=")
    34.             ii = InStr(i + 1, strTestData, ";")
    35.                 If i < ii And i <> 0 Then
    36.                     strDepth = Mid(strTestData, i, ii - i)
    37.                 End If
    38.             blnStartReading2 = True
    39.         End If
    40.      
    41.       If strTestData = "EndHeader" Then blnStartReading1 = True
    42.       If strTestData = "STOP" Then blnStartReading2 = False
    43.      
    44.     Wend
    45. Close #2
    46. End Sub
    Attached Files Attached Files
    Last edited by junlo; Feb 6th, 2007 at 12:30 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width