- Imports System.Collections.Generic
- Imports System.ComponentModel
- Imports System.Data
- Imports System.Drawing
- Imports System.Text
- Imports System.Windows.Forms
- Imports System.CodeDom.Compiler
- Imports System.Reflection
- Imports Microsoft.CSharp
- ' code converted to http://www.developerfusion.com/tools/convert/csharp-to-vb/
- ' not checked
- Namespace FUDBuilder
- Public Partial Class frmMain
- Inherits Form
- Private compiler As New VBCodeProvider()
- Public Sub New()
- InitializeComponent()
- End Sub
- Private Sub frmMain_Load(sender As Object, e As EventArgs)
- ' some sample code that shows a message box
- Dim code As String = "Imports System" & vbCrLf & "Imports System.Windows.Forms" & vbCrLf & "Namespace TestCode" & vbCrLf & "Class TestClass" & vbCrLf & "Public Sub Main()" & vbCrLf & "MessageBox.Show(""Hello, runtime compiled world!"")" & vbCrLf & "End Sub" & vbCrLf & "End Class" & vbCrLf & "End Namespace"
- Compile(code, "compiled.exe")
- End Sub
- Private Sub Compile(code As String, fileName As String)
- Dim cparams As New CompilerParameters()
- cparams.GenerateExecutable = True
- ' we want to build an EXE
- cparams.GenerateInMemory = False
- ' don't generate this in memory
- cparams.OutputAssembly = fileName
- ' set the output file name
- cparams.ReferencedAssemblies.Add("System.dll")
- cparams.ReferencedAssemblies.Add("System.Windows.Forms.dll")
- cparams.CompilerOptions = "/optimize /target:winexe"
- ' optimise and set the target to a WinForms application (change to /target:exe if you want console)
- ' compile
- Dim result As CompilerResults = compiler.CompileAssemblyFromSource(cparams, code)
- ' if there are errors in the code, tell the user
- For Each [error] As CompilerError In result.Errors
- MessageBox.Show(String.Format("Line {0}: Error {1} - {2}", [error].Line, [error].ErrorNumber, [error].ErrorText))
- Next
- End Sub
- End Class
- End Namespace
Code Compiler (VB)
Posted by Anonymous on Thu 25th Nov 2010 18:13
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.