|
-
May 30th, 2008, 12:18 PM
#1
Thread Starter
Addicted Member
[RESOLVED] TextBox If Condition And Replace
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
-
May 30th, 2008, 12:20 PM
#2
Fanatic Member
Re: TextBox If Condition And Replace
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.
-
May 30th, 2008, 12:32 PM
#3
Thread Starter
Addicted Member
Re: TextBox If Condition And Replace
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
-
May 30th, 2008, 12:52 PM
#4
Re: TextBox If Condition And Replace
So, try
Code:
If Text1.text = 12JAMAL & VbCrlf & 13MIKE Then
Text1.Text = Replace(Text1.Text,"12JAMAL","")
End If
-
May 30th, 2008, 01:01 PM
#5
Hyperactive Member
Re: TextBox If Condition And Replace
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
-
May 30th, 2008, 01:12 PM
#6
Re: TextBox If Condition And Replace
How does the text get into the textbox in the first place?
-
May 30th, 2008, 01:24 PM
#7
Thread Starter
Addicted Member
Re: TextBox If Condition And Replace
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
-
May 30th, 2008, 01:45 PM
#8
Re: TextBox If Condition And Replace
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...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
May 30th, 2008, 01:48 PM
#9
Fanatic Member
Re: TextBox If Condition And Replace
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?
-
May 30th, 2008, 02:05 PM
#10
Thread Starter
Addicted Member
Re: TextBox If Condition And Replace
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
-
May 30th, 2008, 02:43 PM
#11
Thread Starter
Addicted Member
Re: TextBox If Condition And Replace
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
Last edited by jamal464; May 30th, 2008 at 02:49 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|