sub main() ' News Headlines - 12/22/99 Steve Coles (Version 1.3) ' ' This is an updated, updated version of the previous news scripts. It compiles all eight ' previous scripts into one. Thanks Rich for that suggestion! ' ' This script retrieves and reads brief news summaries. This script lets you choose ' from eight different types of news. When it asks you what kind of news you want to hear, ' the script lists all eight types. If you feel this is too long to listen to, or there are ' types of news you may never want to hear, you only need to delete a word or two and a few ' lines to get rid of them. ' ' You may also say "Cancel" when it asks you want kind of news you want to hear to exit out ' of the script. ' ' Define variables Dim strNews Dim strType Dim strExt Dim intSearchEnd Dim strHeadline(30) Dim strStory(30) Dim nStartPos Dim nEndPos Dim nEndPos2 Dim c, i hs.speak "What kind of news would you like to hear? You may choose from Top Stories, World, Business, Sports, Political, Science, Technology, or Health.", True ' clear out the last voice command recognized hs.LastVoiceCommand = "" ' create our own private recognition list hs.AddVoiceCommand "top stories" hs.AddVoiceCommand "world" hs.AddVoiceCommand "business" hs.AddVoiceCommand "sports" hs.AddVoiceCommand "political" hs.AddVoiceCommand "science" hs.AddVoiceCommand "technology" hs.AddVoiceCommand "health" hs.AddVoiceCommand "cancel" ' start listening hs.StartListen ' wait for and check voice command Do s = hs.LastVoiceCommand If s = "top stories" Then strType = "top stories" strExt = "ts" Exit Do End if If s = "world" Then strType = "world news" strExt = "wl" Exit Do End if If s = "business" Then strType = "business news" strExt = "bs" Exit Do End if If s = "sports" Then strType = "sports news" strExt = "sp" Exit Do End if If s = "political" Then strType = "political news" strExt = "pl" Exit Do End if If s = "science" Then strType = "science news" strExt = "sc" Exit Do End if If s = "technology" Then strType = "technology news" strExt = "tc" Exit Do End if If s = "health" Then strType = "health news" strExt = "hl" Exit Do End if If s = "cancel" then hs.speak "Cancelled. Maybe I can read the news to you later.", True Exit sub End if hs.WaitEvents Loop hs.speak "Retrieving " & strType & ". Please wait.", True strNews = hs.GetURL("dailynews.yahoo.com","/tx/" & strExt & "/index.html", False, 80) ' Download HTML file into string If strNews = "" Or Len(strNews) = 0 Then hs.speak "Sorry, I could not retrieve " & strType & ".", True Exit Sub End If ' Filter and sort news intSearchEnd = InStr(strNews, "Earlier Stories") c = 1 nEndPos = 1 Do nStartPos = InStr(nEndPos, strNews, ".html" & Chr(34) & ">", vbTextCompare) If nStartPos >= intSearchEnd Then c = c - 1 Exit Do End If nEndPos = InStr(nStartPos, strNews, "") strHeadline(c) = Mid(strNews, nStartPos + 10, nEndPos - nStartPos - 10) nStartPos = InStr(nEndPos, strNews, "
", vbTextCompare) nEndPos2 = InStr(nEndPos, strNews, "

", vbTextCompare) strStory(c) = Mid(strNews, nStartPos + 18, nEndPos2 - nStartPos - 18) c = c + 1 Loop ' Report results hs.speak "There are " & c & " news stories", True If c = 1 then hs.speak "Would you like me to read it to you?", True Else hs.speak "Would you like me to read them to you?", True End if ' clear out the last voice command recognized hs.LastVoiceCommand = "" ' create our own private recognition list hs.AddVoiceCommand "yes" hs.AddVoiceCommand "no" ' start listening hs.StartListen ' wait for a voice command Do s = hs.LastVoiceCommand If s <> "" Then Exit Do hs.WaitEvents Loop ' check the actual command If s <> "yes" Then hs.speak "Ok, maybe later", True Exit Sub End If ' read the source and each article hs.speak strTitle i = 1 Do Until i > c hs.speak "News item number " & CStr(i) hs.speak strHeadline(i), True hs.speak strStory(i), True i = i + 1 Loop hs.speak "That's all the " & strType & ".", True End Sub