Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

Create Property

 

 

Instructions

  1. In VS.NET start the macros ide
  2. Next create a new code file by clicking "Project -> Add new item"
  3. Then copy and paste the code below in the code file you just created
    Private Sub CreateProp(Optional ByVal DoGet As Boolean = True, Optional ByVal DoSet As Boolean = True)
        Dim TD As TextDocument
        Dim strVarible, strCode, strType, strName As String
        Dim lngOrigLine As Integer
 
        TD = CType(DTE.ActiveDocument.Object("TextDocument"), TextDocument)
        lngOrigLine = TD.Selection.TopPoint.Line
 
        strVarible = TD.Selection.Text.Trim
        If strVarible.Length = 0 Then
            Dim strVName As String
            strVName = InputBox("Specify the name of the varible to wrap ...").Trim
            If strVName.Length = 0 Then Exit Sub
 
            Dim strVType As String
            strVType = InputBox("Specify the name of the data type for the property ...")
            If strVType.Length = 0 Then Exit Sub
 
            strVarible = strVName & " As " & strVType
        End If
 
        If strVarible.ToUpper.IndexOf(" AS ") > 0 Then
            strType = strVarible.Substring(strVarible.ToUpper.IndexOf(" AS ") + 4).Trim
            If strType.Trim.ToLower.StartsWith("new ") Then
                strType = strType.Substring(strType.Trim.ToLower.IndexOf("new ") + 4)
            End If
            If strType.Trim.ToLower.IndexOf("(") <> -1 Then
                strType = strType.Substring(0, strType.Trim.ToLower.IndexOf("("))
            End If
            strVarible = strVarible.Substring(0, strVarible.ToUpper.IndexOf(" AS ")).Trim
        Else
            strType = InputBox("Selection does not encompas '... As >Type<'")
            If strType.Length = 0 Then Exit Sub
        End If
 
        strName = InputBox("Specify the name of the property genereate ...", , strVarible).Trim
        If strName.Length = 0 Then Exit Sub
 
 
        strCode = vbCrLf
        If DoGet And DoSet Then
            strCode &= "    Public Property " & strName & "() As " & strType & vbCrLf
        ElseIf DoGet And DoSet = False Then
            strCode &= "    Public ReadOnly Property " & strName & "() As " & strType & vbCrLf
        ElseIf DoGet = False And DoSet Then
            strCode &= "    Public WriteOnly Property " & strName & "() As " & strType & vbCrLf
        Else
            strCode &= "    Public Property " & strName & "() As " & strType & vbCrLf
        End If
        If DoGet Then
            strCode &= "        Get" & vbCrLf
            strCode &= "            Return " & strVarible & vbCrLf
            strCode &= "        End Get" & vbCrLf
        End If
        If DoSet Then
            strCode &= "        Set(Byval Value As " & strType & ")" & vbCrLf
            strCode &= "            " & strVarible & " = Value" & vbCrLf
            strCode &= "        End Set" & vbCrLf
        End If
        strCode &= "    End Property" & vbCrLf
 
        '
        'Copy property
        '
 
        Dim ts As TextSelection = TD.Selection 'CType(DTE.ActiveWindow.Selection, EnvDTE.TextSelection)
        Dim ce As CodeElement
        Dim te As EnvDTE.TextPoint
 
        While ce Is Nothing
            ce = ts.ActivePoint.CodeElement(vsCMElement.vsCMElementClass)
            If ce Is Nothing Then
                ce = ts.ActivePoint.CodeElement(vsCMElement.vsCMElementStruct)
                If ce Is Nothing Then
                    ts.StartOfLine()
                    ts.LineDown()
                End If
            End If
        End While
 
        te = ce.GetEndPoint(vsCMPart.vsCMPartBody)
        TD.Selection.MoveToLineAndOffset(te.Line, 0, False)
        TD.Selection.Insert(strCode)
        TD.Selection.GotoLine(lngOrigLine)
        TD.Selection.StartOfLine()
        DoFormatDoc()
    End Sub
 
    Sub CreateGetSetProperty()
        CreateProp(True, True)
    End Sub
 
    Sub CreateGetProperty()
        CreateProp(True, False)
    End Sub
 
    Sub CreateSetProperty()
        CreateProp(False, True)
    End Sub


Now you can use the "CreateGetSetProperty", "CreateGetProperty", and "CreateSetProperty" methods to add wrapper properties for any varible.

Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume