|
-
Nov 25th, 2005, 10:44 AM
#1
Thread Starter
Frenzied Member
[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
-
Nov 25th, 2005, 10:57 AM
#2
Re: SendMessageString!
oops! ok, it was a text file..
Last edited by jcis; Nov 25th, 2005 at 11:13 AM.
-
Nov 25th, 2005, 11:12 AM
#3
Thread Starter
Frenzied Member
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
-
Nov 25th, 2005, 11:13 AM
#4
Re: SendMessageString!
 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.
-
Nov 25th, 2005, 11:18 AM
#5
Thread Starter
Frenzied Member
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
-
Nov 25th, 2005, 11:29 AM
#6
Re: SendMessageString!
Then you could do something like this:
VB Code:
Dim tmp As String
Private Sub Command1_Click()
If tmp Like "*Text to be compared*" Then
MsgBox "The string is in the file"
End If
End Sub
Private Sub Form_Load()
Open "C:\YourFile.txt" For Binary As #1
tmp = Space(LOF(1))
Get #1, , tmp
Close #1
End Sub
Last edited by jcis; Nov 25th, 2005 at 08:04 PM.
-
Nov 25th, 2005, 11:33 AM
#7
Re: SendMessageString!
Okay then open the file and use instr?? Whats wrong??
-
Nov 25th, 2005, 01:30 PM
#8
Thread Starter
Frenzied Member
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
-
Nov 25th, 2005, 01:40 PM
#9
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.
-
Nov 25th, 2005, 01:44 PM
#10
Re: SendMessageString!
Something like this should find a string
VB Code:
Option Explicit
Private Sub Form_Load()
Dim x As Integer
Dim ff As Integer
Dim strBuff As String
ff = FreeFile
Open App.Path & "\to do.txt" For Input As #ff
strBuff = Input(LOF(ff), ff)
Close #ff
x=instr(strbuff,text1.text)
if x > 0 then
strRetValue = mid$(strBuff,x,len(text1.text))
msgbox "Found"
else
msgbox "Not Found"
endif
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|