Results 1 to 11 of 11

Thread: [RESOLVED] TextBox If Condition And Replace

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    233

    Resolved [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

  2. #2
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    233

    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

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: TextBox If Condition And Replace

    So, try
    Code:
    If Text1.text = 12JAMAL & VbCrlf & 13MIKE Then
        Text1.Text = Replace(Text1.Text,"12JAMAL","")
    End If

  5. #5
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    376

    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

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: TextBox If Condition And Replace

    How does the text get into the textbox in the first place?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    233

    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

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  9. #9
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    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?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    233

    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

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    233

    Re: TextBox If Condition And Replace

    Hi

    I solve it like that with commandbutton

    vb Code:
    1. Text1.Text = Replace(Text1.Text,"12JAMAL", & vbCrlf & vbNullString)
    2.  
    3. 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
  •  



Click Here to Expand Forum to Full Width