Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VB.Net intellisense comment header
Message
From
13/08/2003 13:01:58
Andrew Fell-Gordon
Calypso Publications Ltd
Enfield, United Kingdom
 
 
To
06/08/2003 14:40:31
Jacci Adams
Lindsay-Adams Consulting
Louisville, Ohio, United States
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00817428
Message ID:
00819844
Views:
21
>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

        ' get the preceding declaration
        DTE.ActiveDocument.Selection.lineUp(1)
        DTE.ActiveDocument.Selection.selectline()
        line = DTE.ActiveDocument.Selection.text
        DTE.ActiveDocument.Selection.Collapse()
        DTE.ActiveDocument.Selection.startofline()
        ' DTE.ActiveDocument.Selection.lineDown(1)

        proctypepos = line.IndexOf("Sub")
        If proctypepos > -1 Then
            ' we have a subroutine
            ProcType = "' Procedure: "
            pType = "P"
            ReturnVal = "Void"
        Else
            proctypepos = line.IndexOf("Function")
            If proctypepos > -1 Then
                ' we have a function
                ProcType = "' Function: "
                pType = "F"
                ' find the return type
                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
                ' we have an unknown
                ProcType = "' Unknown!: "
                pType = "X"
                ReturnVal = "??"
                proctypepos = -1
            End If
        End If
        If proctypepos > -1 Then
            ' get the procedure name
            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

        ' Visibility
        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

        ' Parameters
        If line.IndexOf("()") > -1 Then
            ' there are no parameters
            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
        ' Write the comment block
        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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform