>Is there a way to program .Net intellisense to insert a comment header block when I type "hdr" like in VFP inside my VB.NET code behind pages?
>
>TIA,
>Jacci
In principle it is very similar to VFP. You create a macro that writes the comment block. This is a very VBA-like script that manipulates the text. If you've used Word VBA it should be pretty straightforward. Here is the macro that I use. It basically assumes that you are putting the header on the line immediately after the procedure declaration so it gets that line and parses it. Then it writes the header block. The parsing is pretty basic and you could definitely improve it. But it's a start
Sub hdr()
Dim line As String
Dim ProcType As String
Dim pType As String
Dim Visibility As String
Dim ReturnVal As String
Dim params(0, 4) As String
Dim paramline() As String
Dim nextspace As Integer
Dim proctypepos As Integer
Dim procname As String
Dim x As Integer
DTE.ActiveDocument.Selection.lineUp(1)
DTE.ActiveDocument.Selection.selectline()
line = DTE.ActiveDocument.Selection.text
DTE.ActiveDocument.Selection.Collapse()
DTE.ActiveDocument.Selection.startofline()
proctypepos = line.IndexOf("Sub")
If proctypepos > -1 Then
ProcType = "' Procedure: "
pType = "P"
ReturnVal = "Void"
Else
proctypepos = line.IndexOf("Function")
If proctypepos > -1 Then
ProcType = "' Function: "
pType = "F"
Dim sep() As Char = {" ", ",", "(", ")"}
Dim words() As String = line.Split(sep)
If words(words.GetUpperBound(0) - 1) = "As" Then
ReturnVal = words(words.GetUpperBound(0))
Else
ReturnVal = "Boolean"
End If
Else
ProcType = "' Unknown!: "
pType = "X"
ReturnVal = "??"
proctypepos = -1
End If
End If
If proctypepos > -1 Then
nextspace = line.IndexOf(" ", proctypepos)
If nextspace > -1 Then
Dim shortline As String = line.Substring(nextspace + 1).Trim()
nextspace = shortline.IndexOf("(")
If nextspace > -1 Then
procname = shortline.Substring(0, nextspace)
Else
procname = shortline
End If
Else
procname = "??"
End If
Else
procname = ""
End If
If line.IndexOf("Public") > -1 Then
Visibility = "Public"
ElseIf line.IndexOf("Protected Friend") > -1 Then
Visibility = "Protected Friend"
ElseIf line.IndexOf("Protected") > -1 Then
Visibility = "Protected"
ElseIf line.IndexOf("Private") > -1 Then
Visibility = "Private"
ElseIf line.IndexOf("Friend") > -1 Then
Visibility = "Friend"
Else
Visibility = "??"
End If
If line.IndexOf("()") > -1 Then
ReDim paramline(0)
paramline(0) = "None"
Else
Dim startparam As Integer
Dim endparam As Integer
Dim paramstring As String
startparam = line.IndexOf("(")
endparam = line.IndexOf(")")
paramstring = line.Substring(startparam + 1, endparam - (startparam + 1))
paramline = paramstring.Split(",")
End If
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "'********************************************"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & ProcType & procname
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Author: Andrew Fell-Gordon"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Created: " & CStr(Now())
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Function: "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Visibility: " & Visibility
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Parameters:"
For x = 0 To paramline.GetUpperBound(0)
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "'" & ControlChars.Tab & paramline(x)
Next
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Return Value: " & ReturnVal
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "'*********************************************"
DTE.ActiveDocument.Selection.NewLine()
End Sub
I am sure this can be done better as I wrote this early in my vb.net days (six months ago!). If anyone can suggest improvements I'd be glad to know.
I havn't been able to associate it with a string in the text window as VFP does but I've linked it to a function key ALT+SHIFT+H which is used for something to do with images in C# and which I'm not likely to use.
Hope this helps
Andrew