-
Hey sup? My problem is this: I use an Inet control to retrieve a page's HTML and then I need a code to return a word from a line in that HTML. For example I have this HTML code:
Code:
<HTML>
<HEAD>
<Title>Hey</Title>
</Head>
<Body>
Page content
</BOdy>
</HTML>
and I want to retrieve the word "Page" by using it's coordinates. By coordinates I mean it's line number and word number! When I use the function with the parameters of Line 6 and Word 1, I want it to return the word "Page"! Does anyone know how I can do that! I had a code before but it didn't work properly! Can you please see if your code works before you give it to me, because this program takes very long to load and running it many times with a bad coad may cause any system to restart or freeze! Thanx for your help in advance!
-
-
Make so that your code skips everything until it comes to <BODY>. Save the position to long after <BODY>. Then look for </BODY>. Save it's position to long. Cut the area in to string.
It's better if you code this one yourself, it's not fun to copy everything and not to think yourself :)
Hope this helps,
-
Use a RichTextBox and take a look at it's Find property in the Object Browser.
-
I got a example of how you can find your line.
But you have to start with line zero of counting the lines. ;)
Code:
Private Function GetLine(iLine As Integer, FileName As String) As String
On Error GoTo Err_ReadFile
Dim sLine As String
Dim Infile As Integer
Dim LineCount As Integer
LineCount = 0
Infile = FreeFile
' Open the file for reading
Open (FileName) For Input As Infile
' Check if there are any data aviable the file
If EOF(Infile) = True Then GoTo Err_ReadFile
' Read all the lines in the file
Do Until EOF(Infile)
Line Input #Infile, sLine
If LineCount = iLine Then
Exit Do
End If
LineCount = LineCount + 1
Loop
' Well we got our string from the selected line.
GetLine = sLine
' Close the file
Close Infile
Exit Function
Err_ReadFile:
' Close the file.
Close Infile
End Function
USe this function to find your line ( "like 6" ). :)
Code:
Dim myLine As String
' The rest is up to you.. :-) of finding the right word.
myLine = GetLine(6, "C:\Test.html")
Goodluck.
[Edited by kayoca on 11-09-2000 at 11:53 AM]
-
Can anyine else give me a better code!
-
Might be a bit more bugfree than the last one i posted
Code:
Function Retlineword(Text As String, line As Long, word As Long)
Dim lines() As String, words() As String, buffer As String, x&, n&, max&
If Len(Text) Then
lines = Split(Text, vbCrLf)
If line - 1 <= UBound(lines) Then
If Len(lines(line - 1)) Then
words = Split(lines(line - 1), " ")
max = UBound(words)
If word <= max Then
For x = 0 To max
If n > max Then Exit For
If n <> x Then words(x) = words(n)
If words(x) = vbNullString Then x = x - 1
n = n + 1
Next x
ReDim Preserve words(x)
If word <= x Then
Retlineword = words(word - 1)
End If
End If
End If
End If
End If
End Function
-