Re: search through text box
you can put the file in list box. write the file again without the line u enter.
Re: search through text box
i am looking for something which searches and removes the item i want in a text box. i prefer not to use a list box. thanks anyway
Re: search through text box
Try using the replace function.
Text1.text = replace(Text1.Text,"Line1","")
This will remove every occurrence of "Line1"
Re: search through text box
text1.text = replace(text1.text, "line1", "")
edit: snap
Re: search through text box
Quote:
Originally Posted by westconn1 and Caskbill
Text1.text = replace(Text1.Text,"Line1","")
Eh! That will leave some blank lines there and it also replaces "Line11" with "1", "xyzLine1abc" with "xyzabc".
How about this:
Code:
'-- vbLf and vbCr are added to front and back to make sure
'-- the first and last lines will be also removed if matched.
sText = vbLf & Text1.Text & vbCr
sItem = vbLf & Text2.Text & vbCr
sText = Replace(sText, sItem, "")
Text1.Text = Mid$(sText, 2, Len(sText) - 2) '-- remove added chars
Re: search through text box
Quote:
Code:
'-- vbLf and vbCr are added to front and back to make sure
'-- the first and last lines will be also removed if matched.
sText = vbLf & Text1.Text & vbCr
sItem = vbLf & Text2.Text & vbCr
sText = Replace(sText, sItem, "")
Text1.Text = Mid$(sText, 2, Len(sText) - 2) '-- remove added chars
i just tried that and after clicking a commnd button nothing happened. i had two text boxes with multiline set as well as scroll bars
Re: search through text box
Quote:
Originally Posted by adam786
i just tried that and after clicking a commnd button nothing happened. i had two text boxes with multiline set as well as scroll bars
It worked for me, how are you doing it?
Re: search through text box
firstly i opened up vb 6 and click exe
then added 2 text boxes
then set the 2 text boxes to multiline and scroll bars (both ver and hori)
added a command button and added code to command button
clicked run and does not do anything.
Re: search through text box
Let's try to define the problem better, primarily because AnHn noticed that the problem is not that simple. You have three possibilities that have to be handled. The last line of a multi-line text box could have:
(1) VbCrLf and nothing else
(2) a string without VbCrLf at the end
(3) A string with VbCrLF at the end
The other lines have at least VbCrLF and may or may not have a string preceding it. It appears that you want the code to (A) get rid of all double line spacing first and then (B) examine the last line, which could now be any of (1) through (3) above, and delete any line within the text box that matches it, including the VbCrLf on that line, thus repacking the text box.
Is that correct?
1 Attachment(s)
Re: search through text box
Duh! Everything said and done, just use this simple piece of code. This will work just you want it to. Note that you will need two textboxes (one will contain the data and the other will contain the line which you want to remove) and one command button. When you click on the command button, your specified line will be removed.
PLUS, this code has been tested for functionality and I'm including a working form file which you can dnld and use.
Code:
Private Sub Command1_Click()
Dim srch As String, linedata As String
Dim i As Integer
Text1.Tag = ""
For i = 1 To 50 'enough for 50 lines. extend the loop to as much as required
If InStr(Text1.Text,vbNewLine) = 0 Then
linedata = Text1.Text
Text1.Text = ""
Else
linedata = Left(Text1.Text,InStr(Text1.Text,vbNewLine)-1)
Text1.Text = Mid(Text1.Text,Instr(Text1.Text,vbNewLine)+2)
End If
If linedata <> Text2.Text Then
If Text1.Tag <> "" Then Text1.Tag = Text1.Tag & vbNewLine
Text1.Tag = Text1.Tag & linedata
End If
If Text1.Text = "" Then Exit For
Next i
Text1.Text = Text1.Tag
End Sub
Re: search through text box
Quote:
Originally Posted by lone_REBEL
Just use this simple piece of code. This will work. Note that you will need two text boxes. One will contain the data and the other will contain the line that you want to remove. You also need a command button. When you click on the command button, your specified line will be removed. This code has been tested for functionality, and I'm including a working form file.
Code:
Private Sub Command1_Click()
Dim srch As String, linedata As String
Dim i As Integer
Text1.Tag = ""
For i = 1 To 50 'enough for 50 lines. extend the loop to as much as required
If InStr(Text1.Text,vbNewLine) = 0 Then
linedata = Text1.Text
Text1.Text = ""
Else
linedata = Left(Text1.Text,InStr(Text1.Text,vbNewLine)-1)
Text1.Text = Mid(Text1.Text,Instr(Text1.Text,vbNewLine)+2)
End If
If linedata <> Text2.Text Then
If Text1.Tag <> "" Then Text1.Tag = Text1.Tag & vbNewLine
Text1.Tag = Text1.Tag & linedata
End If
If Text1.Text = "" Then Exit For
Next i
Text1.Text = Text1.Tag
End Sub
Good job, 'Rebel. :thumb: