Quick VB.NET Property builder (written in VB6) for your pleasure 
Author Message
 Quick VB.NET Property builder (written in VB6) for your pleasure

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



Mon, 18 Oct 2004 04:00:50 GMT  
 Quick VB.NET Property builder (written in VB6) for your pleasure

Why cannot you use macro in IDE?

Mikhail Berlyant
Data Integrator, Data Systems
Launch Your Yahoo!Music Experience  http://launch.yahoo.com
Brainbench MVP for Visual Basic   www.brainbench.com

  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



Mon, 18 Oct 2004 04:14:04 GMT  
 Quick VB.NET Property builder (written in VB6) for your pleasure

There is a very good reason why you cant use the macro, because I didn't know it existed. The macro editor ROCKS!

Thank you for bringing that to my attention!


  Why cannot you use macro in IDE?

  Mikhail Berlyant
  Data Integrator, Data Systems
  Launch Your Yahoo!Music Experience  http://launch.yahoo.com
  Brainbench MVP for Visual Basic   www.brainbench.com

    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



Mon, 18 Oct 2004 04:18:09 GMT  
 Quick VB.NET Property builder (written in VB6) for your pleasure

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



Mon, 18 Oct 2004 05:04:57 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB.NET property builder macro ..?

2. Layout builder for VB6/WinForms .NET released

3. Ann: Layout builder for VB6/WinForms .NET released

4. Ann: Layout builder for VB6/WinForms .NET released.

5. Layout builder for VB6/WinForms .NET released

6. Ann: Layout builder for VB6/WinForms .NET released.

7. Re-writing Quick Basic to VB

8. Quick data browsing over internet using vb.net?

9. VB.NET and MS SQL 2k quick question...

10. VB.NET and MS SQL 2k quick question...

11. Crystal Reports 8.5 (VB6) to Crystal Reports NET (VB.NET) conversion

12. Converting VB6 to VB.NET without a full VB6 project

 

 
Powered by phpBB® Forum Software