Here is the code for the .NET Macro IDE, just select the Vars like before, then run the macro. Make sure your vars start with a lower case letter or two (example: Private m_strText as String)
.NET CODE:
Public Module IDETools
Private Function GetFirstCapIndex(ByVal strString As String) As Integer
Dim i As Integer
Dim sChr As String
For i = 1 To Len(strString)
sChr = Mid(strString, i, 1)
If sChr = UCase(sChr) Then
If sChr <> LCase(sChr) Then
GetFirstCapIndex = i
Exit Function
End If
End If
Next
End Function
Sub PropertyFromVars()
Dim txtVars As String = DTE.ActiveDocument.Selection.text
Dim Scope As String = "Public"
Dim i As Integer
Dim s As String
Dim sx() As String
Dim sxa() As String
Dim ActSel As TextSelection = DTE.ActiveDocument.Selection
s = Replace(txtVars, "Private ", "", , , vbTextCompare)
s = Replace(s, "Public ", "", , , vbTextCompare)
s = Replace(s, "Friend ", "", , , vbTextCompare)
s = Replace(s, "Protected ", "", , , vbTextCompare)
sx = Split(s, vbCrLf)
s = ""
For i = 0 To UBound(sx)
If sx(i) <> "" Then
sxa = Split(sx(i), " as ", , vbTextCompare)
sxa(1) = Trim(sxa(1))
sxa(0) = Trim(sxa(0))
s = s & Scope & " Property " & Mid(sxa(0), GetFirstCapIndex(sxa(0))) & "() As " & sxa(1) & vbCrLf
s = s & " Get" & vbCrLf
s = s & " Return " & sxa(0) & vbCrLf
s = s & " End Get" & vbCrLf
s = s & " Set (ByVal Value As " & sxa(1) & ")" & vbCrLf
s = s & " " & sxa(0) & " = Value" & vbCrLf
s = s & " End Set" & vbCrLf
s = s & "End Property" & vbCrLf & vbCrLf
End If
Next
'ActSel.Text &= vbCrLf & vbCrLf & s
ActSel.EndOfLine()
ActSel.Insert(vbCrLf & vbCrLf & vbCrLf)
ActSel.Insert(s)
End Sub
End Module
I was getting tired of writing class properties in .NET so I made this dirty little VB6 app to do it for me. Just drop this code in a form that has a CommandButton(Command1), a TextBox (Text1), and a ComboBox (cboScope) and away you go.
Usage: First start your class in .NET... something like this:
Public Class MyClass
'// these will be properties:
Private m_sMake as String
Private m_sManuf as String
Private m_iYear as Integer
End Class
Then, Copy all of your variables that are going to be used for properties into the VB6 App's TextBox:
Private m_sMake as String
Private m_sManuf as String
Private m_iYear as Integer
Finally, Select the scope of your properties from the combo box, and then click the command button. Now, just go to VB.NET and paste your new property code into the class... here is what you end up with:
Public Property Make() As String
Get
Return m_sMake
End Get
Set (ByVal Value As String)
m_sMake = Value
End Set
End Property
Public Property Manuf() As String
Get
Return m_sManuf
End Get
Set (ByVal Value As String)
m_sManuf = Value
End Set
End Property
Public Property Year() As Integer
Get
Return m_iYear
End Get
Set (ByVal Value As Integer)
m_iYear = Value
End Set
End Property
--------------------------------------------------------
VB 6 CODE:
Option Compare Binary
Public Function GetFirstCapIndex(strString As String) As Integer
Dim i As Integer
Dim sChr As String
For i = 1 To Len(strString)
sChr = Mid(strString, i, 1)
If sChr = UCase(sChr) Then
If sChr <> LCase(sChr) Then
GetFirstCapIndex = i
Exit Function
End If
End If
Next
End Function
Private Sub Command1_Click()
Dim s As String
Dim sx() As String
Dim sxa() As String
s = Replace(Text1.Text, "Private ", "", , , vbTextCompare)
s = Replace(s, "Public ", "", , , vbTextCompare)
s = Replace(s, "Friend ", "", , , vbTextCompare)
s = Replace(s, "Protected ", "", , , vbTextCompare)
sx = Split(s, vbCrLf)
s = ""
For i = 0 To UBound(sx)
If sx(i) <> "" Then
sxa = Split(sx(i), " as ", , vbTextCompare)
sxa(1) = Trim(sxa(1))
sxa(0) = Trim(sxa(0))
s = s & cboScope.Text & " Property " & Mid(sxa(0), GetFirstCapIndex(sxa(0))) & "() As " & sxa(1) & vbCrLf
s = s & " Get" & vbCrLf
s = s & " Return " & sxa(0) & vbCrLf
s = s & " End Get" & vbCrLf
s = s & " Set (ByVal Value As " & sxa(1) & ")" & vbCrLf
s = s & " " & sxa(0) & " = Value" & vbCrLf
s = s & " End Set" & vbCrLf
s = s & "End Property" & vbCrLf & vbCrLf
End If
Next
Clipboard.Clear
Clipboard.SetText s
End Sub