Results 1 to 4 of 4

Thread: [RESOLVED] [HELP] Detect String

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    St. Louis
    Posts
    14

    Resolved [RESOLVED] [HELP] Detect String

    EDIT: Thanks to LaVolpe and jpbro, the code is:
    Code:
    Dim iPos As Integer
    iPos = InStr(1, LogText, "!ban", vbTextCompare)
    If iPos Then 
          banTxt = Mid$(LogText, iPos + 4) ' +4 is length of !ban
          'Command
    Else
    End If

    Hey Guys!
    I had a thread in MSDN Help Center, and they redirected me to this forum as I have VB6. I have the Enterprise version (legal of course), and I need help.

    Code:
    If (InStr(1, LogText, "!ban ", vbTextCompare) > 0) Then
    Call SendMessage(hWndTextbox, WM_SETTEXT, 0, "/ban ")
    Call PostMessage(hWndTextbox, WM_KEYDOWN, VK_RETURN, 0)
    Sleep (75)
    End If
    This is what I am trying to do^. I want to detect text from my chat box in my game. If it detects "!ban XXXXXX" from a user, I want to send a "/ban XXXXXX" from a server hoster (me). How do I detect the input after "!ban "?

    Call SendMessage(hWndTextbox, WM_SETTEXT, 0, "/ban " & "//HERE\\")

    ^


    Thanks In Advanced.
    Last edited by Vlad1k; Feb 9th, 2012 at 03:06 PM. Reason: [RESOLVED]

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [HELP] Detect String

    Welcome to the forums.

    InStr returns the position where !ban was found. To return the characters after that position, use Mid$()
    Code:
    Dim iPos As Integer
    iPos = InStr(1, LogText, "!ban", vbTextCompare)
    If iPos Then 
          banTxt = Mid$(LogText, iPos + 4) ' +4 is length of !ban
          ... send the text
    Else
    
    End If
    But since LogText, I would assume can contain several lines of text, you may also need to test for the end of the line which !ban was found in?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,893

    Re: [HELP] Detect String

    Lavolpe beat me to it.
    Last edited by jpbro; Feb 9th, 2012 at 12:34 PM. Reason: Late to the party

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Location
    St. Louis
    Posts
    14

    Re: [HELP] Detect String

    Thank you LaVolpe, you are a life saver! +REP.

    Thank you jpbro for trying. +REP.

    The code ran perfectly, now I can make major commands for my Server Mod.

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