Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27156

Generate Class.vb File Programmatically

$
0
0
Hello,

I want to create a class builder which will get the tables from the specified database and build my [className].vb file - at the push of a button!

For example:
Code:

        Dim strBuilder As New StringBuilder

        strBuilder.Append("Public class clsExample" & vbCrLf)

        'Create variables
        strBuilder.Append("Private _ID As String")
        strBuilder.Append(vbCrLf)

        'Create properties
        strBuilder.Append("Public Property _ID() As Integer" & vbCrLf)
        strBuilder.Append("Get" & vbCrLf)
        strBuilder.Append("return _ID" & vbCrLf)
        strBuilder.Append("end Get" & vbCrLf)
        strBuilder.Append("Set(ByVal Value As Integer)" & vbCrLf)
        strBuilder.Append("_ID = Value" & vbCrLf)
        strBuilder.Append("End Set" & vbCrLf)
        strBuilder.Append("End Property " & vbCrLf)
        strBuilder.Append(vbCrLf)
        strBuilder.Append(vbCrLf & "End Class")

        Console.Write(strBuilder.ToString())

To get this result in the clsExample.vb file that was created using the previous code
Code:

Public Class clsExample
        Private _ID As String
        Public Property _ID() As Integer
            Get
                Return _ID
            End Get
            Set(ByVal Value As Integer)
                _ID = Value
            End Set
        End Property


    End Class

I'm not sure how to go about telling the program to create the [className].vb file and include my strBuilder as code in the file. Hope this makes sense...

Viewing all articles
Browse latest Browse all 27156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>