Hi
Is it possible to use the Replace funcation with if statment in textbox to replace words if exist
Ex
I have this word to be replaced 12JAMAL but not all the time only in some condition
Printable View
Hi
Is it possible to use the Replace funcation with if statment in textbox to replace words if exist
Ex
I have this word to be replaced 12JAMAL but not all the time only in some condition
Simple answer to what I think is your question: yes.
If I want to replace "12JAMAL" under certain conditions, I'd just test for those conditions then use text1.text=replace(text1.text,"12JAMAL","replaced string") or something similar, where text1 is your textbox.
Thank's drag0n_45
I have only one condition i don't want the word 12JAMAL to be replaced otherwise it should be replaced
This condition is
Text1.text = 12JAMAL & VbCrlf & 13MIKE
What i ment that if i found in the textbox 12JAMAL and followed in the next line 13MIKE then don't replace anything
So, tryCode:If Text1.text = 12JAMAL & VbCrlf & 13MIKE Then
Text1.Text = Replace(Text1.Text,"12JAMAL","")
End If
When do you check your condition(lost focus, keypress)?
Private Sub Text1_LostFocus()
If Text1.Text <> "12JAMAL" & vbCrLf & "13MIKE" Then
Text1.Text = Replace(Text1.Text, "12JAMAL", "")
End If
End Sub
How does the text get into the textbox in the first place?
Thank's Hack
Thank's ggettings
Sorry if i didn't explaine in depth
-------------- Don't replace anything-----------------
In the textbox if the text =
12JAMAL
13MIKE
-------------- Don't replace anything-----------------
--------------replace 12JAMAL with vbNullString-----------------
In the textbox if the text =
12JAMAL
OTHER WORDS
--------------replace 12JAMAL with vbNullString-----------------
Let say text1.text =
12JAMAL 'Keep this one
13MIKE
DDDDD
12SSS
RRRRR
12JAMAL ' This one only to be removed
TTTT7I
TYR567
CVFR76
So after using the Replace funcation text1.text =
12JAMAL
13MIKE
DDDDD
12SSS
RRRRR
TTTT7I
TYR567
CVFR76
Thank's
If I understood you correctly then you need to to first transfer the data to an array using the code
Dim Lines() As String = Split(TextBox1.Text, vbCrLf)
Then Sort the array and then replace duplicate values. If you want to replace only "12JAMAL" then you don't need to sort. Simply loop thru the array and find a second occurance of "12JAMAL" and delete it.
After you are done, transfer the data back to textbox....
Hope this helps...
It looks like he just wants to remove "12JAMAL" from the textbox if it is there - if that's the case, then you can just use that replace statement i said in the previous post.
When do you want the replacing to occur? While the user is typing? When the focus leaves the textbox? After a certain time period?
Thank's koolsid
I will try your slotion
Thank's drag0n_45
I want to remove all the word 12JAMAL if it is not followed in the next line with 13MIKE
If it is followed by 13MIKE in the next lint then keep 12JAMAL and remove the other not followed by 13MIKE
Hi
I solve it like that with commandbutton
vb Code:
Text1.Text = Replace(Text1.Text,"12JAMAL", & vbCrlf & vbNullString) Text1.Text = Replace(Text1.Text,"13MIKE", "12JAMAL" & vbCrlf & "13MIKE")
Thank's all