From what you've given us, that's about the best I can do. That certainly gives you a way to save lines in a text file upon each occurrence of some event.
You say "Save" though. Do you mean "Save to File", or do you mean something else?
Take Care,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
This sounds very strange. I suppose if you really want to do such a thing you might crack open that fine manual though. Everything you need is in the MSN Library docs that come with legal copies of VS/VB 6.0:
Code:
Option Explicit
Private Const EM_GETLINECOUNT As Long = &HBA&
Private Const EM_GETLINE As Long = &HC4&
Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Sub Form_Load()
Dim F As Integer
F = FreeFile(0)
Open "original.txt" For Input As #F
Text1.Text = Input$(LOF(F), #F)
Text1.SelStart = 0
Close #F
End Sub
Private Sub Form_Resize()
If WindowState <> vbMinimized Then
With Text1
.Move 0, 0, ScaleWidth / 2, ScaleHeight
Text2.Move .Width, 0, ScaleWidth - .Width, .Height
End With
End If
End Sub
Private Sub mnuGo_Click()
Const MAX_WIDTH As Long = 2048 'Some reasonable value, or you could use a varying
'length buffer by querying with EM_LINEINDEX and
'then EM_LINELENGTH for each line as you go.
Dim LineCount As Long
Dim LineBuffer As String
Dim I As Long
Dim LineChars As Long
Dim F As Integer
LineCount = SendMessage(Text1.hWnd, EM_GETLINECOUNT, 0, 0)
LineBuffer = Space$(MAX_WIDTH)
With Text2
.Visible = False
.Text = vbNullString
For I = 0 To LineCount - 1
Mid$(LineBuffer, 1, 1) = ChrW$(MAX_WIDTH)
LineChars = SendMessage(Text1.hWnd, EM_GETLINE, I, StrPtr(LineBuffer))
.SelText = Left$(LineBuffer, LineChars)
.SelText = vbNewLine
Next
.SelStart = 0
.Visible = True
F = FreeFile(0)
Open "reformatted.txt" For Output As #F
Print #F, .Text;
Close #F
End With
End Sub
Re: [RESOLVED] How i need save Text 1 Each line separate
Hi Everyone,
i Have small problem
I have a comma delimited text file from which I'm reading. After I work the contents of each line & determine it's not a blank line, I write that line into a new text file. So the new file is the same as the original, except any blank lines have been removed.
My problem is that there is always a blank line at the end of the new file. The program that uses this new text file raises an error if there is a trailing blank line.
I try remove this line, If you remove this line will come problem, all lines will merge.
Code:
.SelText = vbNewLine
Last edited by coldlove; Apr 29th, 2018 at 04:14 PM.
Re: [RESOLVED] How i need save Text 1 Each line separate
Use If Right$(MyTextVariable, 2) = vbNewLine Then to test if the text ends with an empty new line (note that the "marker" for new line is 2 characters long).
Use MyTextVariable = Left$(MyTextVariable, Len(MyTextVariable) - 2) to cut off the last two characters from your text.