try this
Code:Option Explicit Dim LipidText() As String Private Sub Form_Load() ReDim LipidText(0) Call ReadFile(App.Path & "\" & "LipidFile.txt") Call ProcessLipid Call WriteFile(App.Path & "\" & "LipidFileNew.txt") End Sub Private Sub ProcessLipid() Dim ComSep() As String Dim LPanel() As String Dim LipidLine As String Dim NewLPanel As String Dim i As Long ' loop through each line in array and process For i = 0 To UBound(LipidText) LipidLine = LipidText(i) ' seperate by comma ComSep() = Split(LipidLine, ",") ' seperate Lipid Panel text by space LPanel() = Split(ComSep(2), " ") ' 5 digit text at position 1 of LPanel array ' check if we have 8 at the start, if we do - we need to process it If Left$(LPanel(1), 1) = "8" Then ' add -90 to it LPanel(1) = LPanel(1) & "-90" End If ' join the LPanel text back into ComSep array ComSep(2) = Join(LPanel, " ") ' restore line and insert into LipidText array LipidText(i) = Join(ComSep, ",") Next i End Sub Private Sub ReadFile(ThisFile As String) Dim f As String Dim ReadLine As String f = FreeFile ' Open file to read Open ThisFile For Input As #f Do Until EOF(f) Line Input #f, ReadLine ' accept data only, skip empty lines If ReadLine <> "" Then LipidText(UBound(LipidText)) = ReadLine ReDim Preserve LipidText(UBound(LipidText) + 1) End If Loop Close #f ' close the file ' remove extra array record ReDim Preserve LipidText(UBound(LipidText) - 1) Form1.Caption = "File Read Successful." End Sub Private Sub WriteFile(ThisFile As String) Dim i As Long Dim f As String f = FreeFile ' open the file to write Open ThisFile For Output As #f ' loop through array and output to file For i = 0 To UBound(LipidText) Print #f, LipidText(i) Next i Close #f ' close the file ' delete array Erase LipidText Form1.Caption = "File write Successful." End Sub




Reply With Quote