Introduction
There are many programs to display headlines from websites but who needs another app burning up resources! You can read the headlines from Visual Studio .NET 2002 with this handy macro.
This has been converted from the VS6 version from VB script to VB.NET. It illustrates that, code can be converted fairly easily, but CreateObject
is probably a thing of the past!
The improved .NET IDE gives some improvements for free. Firstly, hyperlinks are clickable (they will open a webpage) and secondly they will open within Visual Studio.
Install the macro
Run Visual Studio .NET and go to the Tools menu and select Macro and then Macro IDE. Go to the file menu, select Open and the select File. See MSDN for more info on VS Macros.
Modify the macro
Modify the websites as appropriate in the first sub. Assign the macro to a button and that's it. The original tag removal code was found on CodeProject. The conversion of this code was aided by this article. Have fun.
The code
Imports EnvDTE
Imports System.Diagnostics
Imports System.IO
Imports System.Net
Imports System.Text.RegularExpressions
Public Module Headlines
Sub GetHeadlines()
Dim RDFText As String
Dim objTextDoc As TextDocument
Dim objEP As EditPoint
Call DTE.ItemOperations.NewFile("General\Text File")
objTextDoc = DTE.ActiveDocument.Object("TextDocument")
objEP = objTextDoc.StartPoint.CreateEditPoint
RDFText = GetHTML("http://christdot.org/backend.php")
objEP.Insert(stripHTML(RDFText))
objEP.Insert("//###################################_
##########################")
RDFText = GetHTML("http://www.latedecember.com/blogger_rss.xml")
objEP.Insert(stripHTML(RDFText))
objEP.Insert("//###################################_
##########################")
ActiveDocument.Save("C:\news.cpp")
End Sub
Function GetHTML(ByVal strPage As String) As String
Try
Dim oReq As System.Net.HttpWebRequest
Dim oResp As System.Net.HttpWebResponse
oReq = System.Net.HttpWebRequest.Create(strPage)
oResp = oReq.GetResponse
Dim sr As New StreamReader(oResp.GetResponseStream)
Return sr.ReadToEnd()
Catch
End Try
End Function
Function stripHTML(ByVal strInput As String)
strInput = Replace(strInput, "<title>", _
vbCr + vbLf + "<title>")
strInput = Replace(strInput, "</title>", vbCr + _
vbLf + "</title>")
strInput = Replace(strInput, "<description>", vbCr + _
vbLf + "<description>")
strInput = Replace(strInput, "</description>", vbCr + _
vbLf + "</description>")
strInput = Replace(strInput, "<link>", "<link>//")
Dim MyregEx As New Regex("<([^>]|\n\r\n)*>", _
RegexOptions.IgnoreCase)
Dim m As Match = MyregEx.Match(strInput)
strInput = MyregEx.Replace(strInput, "")
strInput = Replace(strInput, "\r\n\r\n", "")
strInput = Replace(strInput, "\n\n", "")
stripHTML = strInput
End Function
End Module
After being created, I spent too much of my childhood with a Dragon 32. Since then I have worked on Personality software, Children's websites, ATM and transport software. Most hobby development is web based and I often have a iPaq in my hand.