Created by: X  

This marco will allow you to add and remove numeric enumerator values from your custom made enumerators.


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

Friend Class frmStartEndValues
    Inherits System.Windows.Forms.Form
 
#Region " Windows Form Designer generated code "
 
    Public Sub New()
        MyBase.New()
 
        'This call is required by the Windows Form Designer.
        InitializeComponent()
 
        'Add any initialization after the InitializeComponent() call
 
    End Sub
 
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
 
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
 
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents lblStart As System.Windows.Forms.Label
    Friend WithEvents nudStart As System.Windows.Forms.NumericUpDown
    Friend WithEvents nudEnd As System.Windows.Forms.NumericUpDown
    Friend WithEvents lblEnd As System.Windows.Forms.Label
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.lblStart = New System.Windows.Forms.Label()
        Me.nudStart = New System.Windows.Forms.NumericUpDown()
        Me.nudEnd = New System.Windows.Forms.NumericUpDown()
        Me.lblEnd = New System.Windows.Forms.Label()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.btnCancel = New System.Windows.Forms.Button()
        CType(Me.nudStart, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.nudEnd, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'lblStart
        '
        Me.lblStart.AutoSize = True
        Me.lblStart.Location = New System.Drawing.Point(8, 8)
        Me.lblStart.Name = "lblStart"
        Me.lblStart.Size = New System.Drawing.Size(63, 13)
        Me.lblStart.TabIndex = 0
        Me.lblStart.Text = "Start Value:"
        '
        'nudStart
        '
        Me.nudStart.Location = New System.Drawing.Point(8, 24)
        Me.nudStart.Maximum = New Decimal(New Integer() {100000000, 0, 0, 0})
        Me.nudStart.Name = "nudStart"
        Me.nudStart.TabIndex = 1
        Me.nudStart.ThousandsSeparator = True
        '
        'nudEnd
        '
        Me.nudEnd.Location = New System.Drawing.Point(8, 72)
        Me.nudEnd.Maximum = New Decimal(New Integer() {100000000, 0, 0, 0})
        Me.nudEnd.Name = "nudEnd"
        Me.nudEnd.TabIndex = 3
        Me.nudEnd.ThousandsSeparator = True
        '
        'lblEnd
        '
        Me.lblEnd.AutoSize = True
        Me.lblEnd.Location = New System.Drawing.Point(8, 56)
        Me.lblEnd.Name = "lblEnd"
        Me.lblEnd.Size = New System.Drawing.Size(60, 13)
        Me.lblEnd.TabIndex = 2
        Me.lblEnd.Text = "Count:"
        '
        'btnOK
        '
        Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.btnOK.Location = New System.Drawing.Point(144, 25)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 4
        Me.btnOK.Text = "OK"
        '
        'btnCancel
        '
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(144, 57)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.TabIndex = 5
        Me.btnCancel.Text = "Cancel"
        '
        'frmStartEndValues
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.AcceptButton = Me.btnOK
        Me.CancelButton = Me.btnCancel
        Me.ClientSize = New System.Drawing.Size(234, 104)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, _
            Me.btnOK, Me.nudEnd, Me.lblEnd, Me.nudStart, Me.lblStart})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmStartEndValues"
        Me.ShowInTaskbar = False
        Me.Text = "Form1"
        CType(Me.nudStart, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.nudEnd, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 
    End Sub
#End Region
End Class

  1. Now we will create a new module and copy the code below into it. Or if you already have a module that you want to place the code into you can do that also.

Public Sub AssignEnumValues()
    Dim idx As Integer = 1
    Dim objform As frmStartEndValues
 
    Try
 
        objform = New frmStartEndValues()
        'AddHandler objform.Activated, AddressOf Formactivate
 
        If objform.ShowDialog = System.Windows.Forms.DialogResult.OK Then
            With CType(DTE.ActiveDocument.Selection, TextSelection)
                .EndOfLine()
                Do
                    .Text = " = " & CStr(objform.nudStart.Value (idx - 1))
                    .LineDown()
                    .EndOfLine()
                    idx = 1
                Loop Until idx > objform.nudEnd.Value
            End With
        End If
 
        objform = Nothing
    Catch
        MsgBox(Err)
    End Try
End Sub
 
Public Sub RemoveEnumValues()
    Dim idx, CurrentLine, Pos As Integer
    Dim objform As frmStartEndValues
 
    Try
        objform = New frmStartEndValues()
        objform.nudStart.Enabled = False
        If objform.ShowDialog = System.Windows.Forms.DialogResult.OK Then
            With CType(DTE.ActiveDocument.Selection, TextSelection)
                CurrentLine = .ActivePoint.Line
                For idx = 1 To CInt(objform.nudEnd.Value)
                    .SelectLine()
                    If .IsEmpty = False Then
                        Pos = .Text.IndexOf(" = ")
                        If Pos > 0 Then .Text = Left(.Text, Pos) & vbCrLf
                    End If
 
                    CurrentLine = 1
                    .GotoLine(CurrentLine, False)
                Next
            End With
        End If
 
        objform = Nothing
    Catch
        MsgBox(Err)
    End Try
End Sub

Now you can use the "RemoveEnumValues" and "AssignEnumValues" methods to add or remove values to a list of enum items.

Contact    Resume
Who is Created by: X?