|
-
Mar 14th, 2006, 04:34 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED]Search
I am searching a document that comes up with for particular values and i need them added to a list box. For example through out my file i may have
xxxxxxxxxxxxxxxxxxxxxxxxxxxidentification=123,56,78,92xxxxxxxxxxxxxxxxxx
where x can represent anything. How do i remove the numbers and the comma's only from copy these numbers from the document and add them to a list box. Take into consideration that there will be an unknown amount of lines identical to the ones above.
Jenova
Last edited by Jenova; Mar 15th, 2006 at 09:55 AM.
-
Mar 14th, 2006, 05:00 PM
#2
Hyperactive Member
Re: Search
the other characters (x's): May some of them be numbers?
-
Mar 14th, 2006, 05:01 PM
#3
Re: Search
You can use InStr() function and loop through each line but I'd recommend to use Reg.Expression so you can set some pattern and get what you want with less effort. We should have some samples available arround here so try searching this forum for "Regular Expression" or similar.
-
Mar 14th, 2006, 05:23 PM
#4
Thread Starter
Hyperactive Member
Re: Search
It is a posibility that the (x) may represent numbers as well. Can anyone provide any examples on Rhino bulls idea? I tried the InStr() function. See Below.
I searched for the identification word in the file and it cam back with an obscene value whic is not correct
VB Code:
Private Sub Form_Load()
Dim Handle As Integer
Dim File As String
Handle = FreeFile
Open "C:\Documents and Settings\Carl\Desktop\index.htm" For Input As Handle
Do While Not EOF(Handle)
File = Input(LOF(Handle), #Handle)
Text1.Text = File
Loop
Close #Handle
End Sub
Private Sub Timer1_Timer()
Static newnum
newnum = InStr(Text1.Text, "identification")
Command1.Caption = newnum
End Sub
This is what i have so far
Last edited by Jenova; Mar 14th, 2006 at 05:27 PM.
-
Mar 14th, 2006, 06:40 PM
#5
Thread Starter
Hyperactive Member
Re: Search
This is quite a hard one then?
-
Mar 14th, 2006, 08:06 PM
#6
Re: [UNSOLVABLE] Search
try this:
VB Code:
Private Sub Form_Load()
Const sFind As String = "identification="
Dim FileNum As Integer
Dim sLine As String
Dim lPos As Long
FileNum = FreeFile
Open "C:\Documents and Settings\Carl\Desktop\index.htm" For Input As #FileNum
Do While Not EOF(FileNum)
Line Input #FileNum, sLine
lPos = InStr(sLine, sFind)
If lPos Then List1.AddItem Mid$(sLine, lPos + Len(sFind), 12)
Loop
Close #FileNum
End Sub
Although without knowing the details of what'll be in the file it's hard to tell if that's the solution you need.
-
Mar 15th, 2006, 08:21 AM
#7
Thread Starter
Hyperactive Member
Re: [UNSOLVABLE] Search
Although without knowing the details of what'll be in the file it's hard to tell if that's the solution you need.
Thanks for the reply bush mobile . In answer to your question i have included a document that i am supposed to be searching. I have made the information i am seacrching for bold to make it more clear.
I need all of those values added to a list box. There will be ALOT more than that in the documents i will be scanning.
Jenova
Last edited by Jenova; Mar 15th, 2006 at 08:44 AM.
-
Mar 15th, 2006, 08:30 AM
#8
Re: [UNSOLVABLE] Search
Ok, try the below. If it's too slow then maybe you'll have to take RB's advice - Regular Expression
VB Code:
Private Sub Form_Load()
Const sFind As String = "domain="
Dim FileNum As Integer
Dim sLine As String
Dim lPos As Long
FileNum = FreeFile
Open "C:\Documents and Settings\Carl\Desktop\index.htm" For Input As #FileNum
Do While Not EOF(FileNum)
Line Input #FileNum, sLine
lPos = InStr(sLine, sFind)
If lPos Then List1.AddItem Mid$(sLine, lPos + Len(sFind), Instr(lPos, sLine, Chr(34)) - lPos + Len(sFind)))
Loop
Close #FileNum
End Sub
-
Mar 15th, 2006, 08:43 AM
#9
Thread Starter
Hyperactive Member
Re: [UNSOLVABLE] Search
Thanks alot, that works great. Only have two questions
What are the following variables for:
sLine
lPos
Jenova
-
Mar 15th, 2006, 08:48 AM
#10
Re: [UNSOLVABLE] Search
Line Input #FileNum, sLine
This tells VB to put the whole line from the file into a string variable called sLine
lPos = InStr(sLine, sFind)
This returns the character position of sFind in sLine. It returns zero if it's not present. We know where the text we want is in relation to lPos, so once we've got it we can extract the text using the Mid Function.
Don't forget to mark this thread resolved if your question has been answered
-
Mar 15th, 2006, 09:55 AM
#11
Thread Starter
Hyperactive Member
Re: [RESOLVED]Search
Thank you!
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
|