Results 1 to 7 of 7

Thread: is this code is possible?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    is this code is possible?

    hi, it is possible to made like with this code?

    lets say...

    i have a Text1.Text and set as multiline = you will right your own message

    then... if the Text1.Text received "HI" i want the msg Box appear Found "HI" then go typing... if Text1.Text received again" hello i want the msg box appear Found "HELLO"

    is this possible?

    i tried like this but get no luck

    VB Code:
    1. Do
    2. if InStr(Text1.Text, "HI") Then
    3. MsgBox("Found: HI")
    4. Else
    5.  
    6. End if
    7.  
    8. if InStr(Text1.Text, "Hello") Then
    9.  
    10. MsgBox("Found: Hello")
    11.  
    12. Else
    13. End if
    14. Loop

    thanks..

  2. #2
    Hyperactive Member vbcode1980's Avatar
    Join Date
    Nov 2005
    Location
    Anywhere the wind blows
    Posts
    365

    Re: is this code is possible?

    Are there specific words you want to find in the text?
    I code C#....

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    Re: is this code is possible?

    yes... example... Hi, Hello, You,

    thanks.

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

    Re: is this code is possible?

    Try
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strSearchFor As String
    3. Dim intFound As Integer
    4.    strSearchFor = "Hi"
    5.    intFound = InStr(Text1.Text, strSearchFor)   ' look for word.
    6.    If intFound Then   ' If found,
    7.       Text1.SelStart = intFound - 1   ' set selection start and
    8.       Text1.SelLength = Len(strSearchFor)   ' set selection length.
    9.       MsgBox "Word found"
    10.    Else
    11.       MsgBox "Word not found."
    12.    End If
    13.  
    14. End Sub

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    Re: is this code is possible?

    @Hack

    your code works... but i dont want to press a command button...

    let say if i type on Text1.Text Hi it will appear automatically the msgbox..

    thanks..

  6. #6
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: is this code is possible?

    just place the code in to the desired event of the textbox like on_change, validate, lostfocus, exit
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

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

    Re: is this code is possible?

    Quote Originally Posted by nokmaster
    @Hack

    your code works... but i dont want to press a command button...

    let say if i type on Text1.Text Hi it will appear automatically the msgbox..

    thanks..
    All code that I post is posted as an example. Generally speaking, I have very little idea of how the member asking the questions wishes to use the code (and often, I have no idea at all).

    If you don't want to use the code in a click event, then move to the Change. I would submit that the keypress event should not be considered unless you want to the code to fire every single time you press a key, which could get very, very annoying to whoever is doing the typing.

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