dcsimg
Results 1 to 12 of 12

Thread: Bot

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    76

    Bot

    okay so i have a text file with a bunch of words.textfile is called"db.txt" and contains words in the following way

    close
    open
    run
    kick

    and so on..

    now i have a textbox and inside the textbox i write the following sentence"i close the door" could some one tell me a simple code that will search the textbox and if anywords from the db.txt are present it will display a msgbox or do something?

    Thanks i really cant figure how to do this..

  2. #2
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Bot

    You can use InStr function to search for the strings
    eg:
    Code:
    If Instr(1,Text1.text,"close") > 0 then
     msgbox "has close"
    end if

    Load the words in the text file to a string array and loop thorugh the array to see any word is in the Text Box.
    IIF(Post.Rate > 0 , , )

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    76

    Re: Bot

    could you help me a bit more because i didnt fully understand what your trying to say.

  4. #4
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Bot

    ok, i full fill the zeezee code.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim fno As Long
    Dim txtline As String
    Dim i As Integer
    
    fno = FreeFile
    Open "c:\db.txt" For Input As #fno
    Do While Not EOF(fno)
       Line Input #fno, txtline
       If InStr(1, Me.Text1.Text, txtline) > 0 Then
          MsgBox "Found"
          Exit Sub
       End If
    Loop
    
    Close (fno)
    
    End Sub

  5. #5
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,698

    Re: Bot

    It would be better if you had the words in a database so you could execute a query against it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Bot

    See the FAQ section to do what you need.
    Here is a Tutorial on File Manipulation
    http://www.vbforums.com/showthread.php?t=405051

    Have you used Arrays before? DO you know how to Loop?
    the Code I gave does the searching for a given text within another text.
    Load each line to an Element in an Array.
    Then for each element in the array, see whether it is in the text boxe's text.

    EDIT: Yikes!!! I m damn slow.
    Last edited by zeezee; Oct 31st, 2007 at 01:32 PM.
    IIF(Post.Rate > 0 , , )

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    76

    Re: Bot

    if i wrote "hello how are you?" i want it to search the string and compaire all the words with the words in the database if it finds a word matching then it will display something in a msgbox or somewhere . okay what would i need to add to the code ? i dont just want it to display "found" if it finds anyword from the db.txt i want to to act according to the word it finds.

    if it finds the word hello in that string i want it to display msgbox"am a bot"
    if it finds the word close i want it to display something else..
    any suggestions?

    thanks again for helping me..
    Last edited by stavrulezz; Oct 31st, 2007 at 01:59 PM.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Bot

    Then each line (or database record) would need two words - the one you type and the one you want the program to respond with:

    hello goodbye
    open close
    etc.

    Find the first one and display the second one.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    76

    Re: Bot

    i dont want it to display words. i just said that for examples.each different word will be a different fuction.i just gave the msgbox" " as an example.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Bot

    What do you mean by "function"? Call a VB function?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    76

    Re: Bot

    yes thats what i mean

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Bot

    Use Select Case
    Code:
    Select Case UCase(Text1.Text)
      Case "HELLO"
        'call the function for hello
      Case "OPEN"
        'call the function for open
      Case 'etc.
    End Select
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width