Results 1 to 20 of 20

Thread: Generate Class.vb File Programmatically

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2013
    Posts
    26

    Generate Class.vb File Programmatically

    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...
    Last edited by Alex_AMF; Mar 2nd, 2013 at 04:45 PM. Reason: Typos

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width