Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21190

VB6 Colspan Enquiry

$
0
0
I'm using the following code to go to a website and gather the tide timetables. I can gather the tide states and times ok, but having a little difficulty in grabbing the tide heights. The problem is that most of the time there are four tides per day, but every so often there is only three which causes my program to error with the runtime error 91.

After some research I think the best approach may be to get the colspan attribute which I can then use to counter the runtime error. Any help or advice would be greatly appreciated.

The code I am using so far is...

For those that want to test this code you will need References to: Microsoft XML, v6.0 and Microsoft HTML Object Library

Dim DateCount As Long
Dim ItemCount As Long
Dim TideData(35, 4) As String
Dim xmlReq As ServerXMLHTTP60
Dim htmlDoc As HTMLDocument, htmlDiv As HTMLHtmlElement, htmlTableBody As HTMLHtmlElement
Set xmlReq = New ServerXMLHTTP60
xmlReq.Open "GET", "http://easytide.ukho.gov.uk/EASYTIDE/EasyTide/ShowPrediction.aspx?PortID=0109B&PredictionLength=7"
xmlReq.send
If xmlReq.Status <> 200 Then MsgBox xmlReq.statusText: Exit Sub
Set htmlDoc = New HTMLDocument
htmlDoc.body.innerHTML = xmlReq.responseText
Set htmlDiv = htmlDoc.getElementsByName("_ctl1_HWLWTable1_pnlHWLW").Item(0)

DateCount = 0
ItemCount = 0

For a = 0 To htmlDiv.getElementsByTagName("TH").length - 1
If IsDate(Format(Mid(htmlDiv.getElementsByTagName("TH").Item(a).innerText, 5, 10), "dd" & "/" & "mm" & "/" & "yyyy")) Then
TideData(a, 0) = Format(Mid(htmlDiv.getElementsByTagName("TH").Item(a).innerText, 5, 10), "dd" & "/" & "mm" & "/" & "yyyy")
If a > 0 Then DateCount = DateCount + 1: ItemCount = 0
Else
TideData(a, 0) = htmlDiv.getElementsByTagName("TH").Item(a).innerText

Set htmlTableBody = htmlDiv.getElementsByTagName("TBODY").Item(DateCount)
TideData(a, 1) = htmlTableBody.getElementsByTagName("TD").Item(ItemCount).innerText

'TideData(a, 2) = htmlTableBody.getElementsByTagName("TD").Item(ItemCount + 4).innerText
'the annointed line above fails when a table on the webage is less than 4 columns

ItemCount = ItemCount + 1
End If
Next a

For z = 0 To 34
Debug.Print z & " " & TideData(z, 0) & " " & TideData(z, 1) & " " & TideData(z, 2)
Next z

Viewing all articles
Browse latest Browse all 21190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>