Results 1 to 10 of 10

Thread: [RESOLVED] SendMessageString!

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Resolved [RESOLVED] SendMessageString!

    In order to find whether a particular item exists in a ListBox, SendMessageString can be used like this:

    lngRetValue = SendMessageString(ListBox1.hWnd, LB_FINDSTRINGEXACT, -1&, "text to be compared")

    In the same way, can SendMessageString be used to find whether a particular text exists in a text file? If so, how?

    Thanks,

    Arpan

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: SendMessageString!

    oops! ok, it was a text file..
    Last edited by jcis; Nov 25th, 2005 at 11:13 AM.

  3. #3

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: SendMessageString!

    I think that doesn't work with a Textbox, but you can do:
    But where from are you getting the TextBox? I am referring to a TEXT FILE & not a TextBox.

    Arpan

  4. #4
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: SendMessageString!

    Quote Originally Posted by arpan_de
    But where from are you getting the TextBox? I am referring to a TEXT FILE & not a TextBox.

    Arpan
    Arpan, its impossible unless you open the file for reading first.

  5. #5

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: SendMessageString!

    Arpan, its impossible unless you open the file for reading first.
    It's pretty obvious that to access data in a text file, the text file has to be opened first. So I guess it goes without saying that the text file has to be opened first to read its contents & do something with that.....

    Arpan

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: SendMessageString!

    Then you could do something like this:

    VB Code:
    1. Dim tmp As String
    2.  
    3. Private Sub Command1_Click()
    4.     If tmp Like "*Text to be compared*" Then
    5.         MsgBox "The string is in the file"
    6.     End If
    7. End Sub
    8.  
    9. Private Sub Form_Load()
    10.     Open "C:\YourFile.txt" For Binary As #1
    11.         tmp = Space(LOF(1))
    12.         Get #1, , tmp
    13.     Close #1
    14. End Sub
    Last edited by jcis; Nov 25th, 2005 at 08:04 PM.

  7. #7
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: SendMessageString!

    Okay then open the file and use instr?? Whats wrong??

  8. #8

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: SendMessageString!

    Then you could do something like this:
    I tried it Jcis but it doesn't work. If I include a MsgBox tmp in the Command1_Click event function, then tmp always turns out to be an empty string.

    Arpan

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: SendMessageString!

    SendMessage (regardless if you have renamed it SendMessageString or not) is used to send messages to different windows (or controls if you like). It is not used to send messages to a file since a file wouldn't be able to respond to such a message. To be able to search a file you need to read the content of it and then do a search in the variable that contains this content. For a regular text file you read it the normal way and then search the string using InStr for example.

    If you want to match a certain line in a text file you can split the lines into an array and search each of them in turn.

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SendMessageString!

    Something like this should find a string

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim x As Integer
    5.   Dim ff As Integer
    6.   Dim strBuff As String
    7.   ff = FreeFile
    8.   Open App.Path & "\to do.txt" For Input As #ff
    9.     strBuff = Input(LOF(ff), ff)
    10.   Close #ff
    11.   x=instr(strbuff,text1.text)
    12.   if x > 0 then
    13.     strRetValue = mid$(strBuff,x,len(text1.text))
    14.     msgbox "Found"
    15.   else
    16.     msgbox "Not Found"
    17.   endif
    18. End Sub

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