I downloaded a tide chart from the web. This way I have the tide info in a file, and I do not have to search the web for it. Before I start fooling around with it, does anyone know what the best way to have hs speak the tide info depending on what day it is? Thanks
Announcement
Collapse
No announcement yet.
Any Ideas on how to parse this tide chart?
Collapse
X
-
beachTags: None
-
Totally untested, but this should give you some ideas and some common scripting functions that may be of use to you.
It assumes the file is in the homeseer \HTML folder. If you do not understand parts of it, just ask. You likely can read the web page using hs.GetURL or hs.GetURLIE rather than putting it in a file then reading the file.
<pre class="ip-ubbcode-code-pre">
Dim iRecords
Dim dDate(100)
Dim sTime(100, 3)
Dim sLevel(100, 3)
sub ParseFile()
'Read the file into a string variable
sData = CreateObject("Scripting.FileSystemObject").OpenTextFile(hs.G etAppPath & "\HTML\Tides.htm").ReadAll
'Organize it into an array of records and remove the   HTML tag
arrDay = split(Replace(sData," ",""),"<br>" & vbCrLf & "<br>")
'iterate each of the day's records
iRecords = ubound(arrDay)
for iDay = 1 to iRecords
'put delimiter at end of record to make parsing easier
sRecord = arrDay(iDay) & "<br>"
'index Front/End of each keyword as looking through record
iFront = instr(sRecord, " ")
iEnd = instr(iFront, "<br>")
'maintain arrrays for each date, and 4 readings for time and level
dDate(iDay) = cDate(mid(sRecord, iFront + 1, iEnd - iFront - 1))
for iReading = 0 to 3
iFront = instr(iEnd,sRecord, "Tide:")
iEnd = instr(iFront, sRecord," E")
sTime(iDay,iReading) = Trim(mid(sRecord,iFront + 1, iEnd - iFront - 1))
iFront = instr(iEnd, sRecord, " ")
iEnd = instr(iFront, sRecord, "<br>")
sLevel(iDay,iReading) = Trim(mid(sRecord,iFront + 1, iEnd - iFront - 1))
Next
Next
end sub
Sub SpeakTides(theDate)
dToday = DateSerial(Year(theDate),Month(theDate),day(theDate)
arrHiLo = Array("high","low")
for iDay = 1 to iRecords
if dToday = dDate(iDay) Then
sText = ""
for iReading = 0 to 3
sHiLo = arrHiLo(iReading mod 2)
sText = sText & sLevel(iDay,iReading) & "inch " & sHiLo & " at " & sTime
if iReading < 3 Then
sText = sText & ", "
end if
next
hs.Speak "Tides for " & Format(theDate,"dddd") & ", " & sText
exit for
end if
Next
End sub
Sub SpeakTodayandTomorrow()
SpeakTides now
SpeakTides DateAdd("d",1,now)
end sub
</pre>
-
beach
Michael,
I tried this one, and it did not work. I don't know if it is supposed to be broken down into several scripts. I ran it and got an error. There was a ")" missing on a line, and when I added it, the error then became "script error in line 0". There is no line zero. I tried to parse the page like I would a regular web page with a simple script but that would not work also.
Comment
-
This is provided to get you started with some ideas of structure and scripting techniques. It was never run and is not expected to work first-time.
If you want to go down this path then make liberal use of the hs.writelog command to look at intermediate results. Just standard debugging and learning as you go.
While I'm happy to provide guidance, the actual making it work is up to you.
I usually find it easier to debug the scripts as vbs file (or event better as VB files if VB compiler is available)
To do this add the following at the top or bottom of the file and rename the file to have a .vbs rather than .txt type.
set hs = CreateObject("Homeseer.Application")
SpeakTidesNow
Then double-click on the filename from Windows Explorer. You will see hs.writelog results in the homeseer log. You can also use Msgbox for more immediate response.
e.g. Msgbox "The data is " & sData
You could also setup an event in HS to run either the vbs as an application or the .txt as a script and use something like a palmpad (or VR phrase) to invoke the event. This will further reduce the number of mouse actions needed to run the script trying to get it to work.
[This message was edited by Michael McSharry on Mon, 16 February 2004 at 10:32 PM.]
Comment
Comment