Hey guys,

I have a big problem that I know I can not work out by myself so I have tried to simplify what I need so I can figure out the bigger picture by myself so here goes.

I borrowed kleinma's open default browser code from the codebank and I want to take the user input url from textbox1 and when button1 is clicked it will create an executable that will launch the domain input into the textbox.

That's the very simple version of it, if someone can help me figure out how to make it work I would REALLY appreciate it! Here is the code I have for this simple form. It has one textbox for user input and one button to generate the exe after user inputs the url into the textbox.

I noticed some code problems in the button1 that I found online, and I'm not sure how to make this work correctly but with kleinma's code you call it like this:

BrowserExec.LaunchNewBrowser(url here)

So I think this code goes into the button1 right? and then is this the correct code to be generating an exe from it? Can anyone give me my missing piece?

vb Code:
  1. Imports Microsoft.Win32
  2. Imports System
  3. Imports System.CodeDom.Compiler
  4. Imports System.ComponentModel
  5. Imports System.Drawing
  6. Imports System.IO
  7. Imports System.Reflection
  8. Imports System.Windows.Forms
  9.  
  10. Public Class Form1
  11.  
  12.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  13.  
  14.     End Sub
  15.  
  16.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  17.  
  18.     End Sub
  19.  
  20.     Public Shared Function Button1_Click((ByVal sourceName As String) As Boolean
  21.  
  22.         Dim sourceFile As FileInfo = New FileInfo(sourceName)
  23.         Dim provider As CodeDomProvider = Nothing
  24.         Dim compileOk As Boolean = False
  25.  
  26.         ' Select the code provider based on the input file extension.
  27.         If sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) = ".CS" Then
  28.  
  29.             provider = New Microsoft.CSharp.CSharpCodeProvider()
  30.  
  31.         ElseIf sourceFile.Extension.ToUpper(CultureInfo.InvariantCulture) = ".VB" Then
  32.  
  33.             provider = New Microsoft.VisualBasic.VBCodeProvider()
  34.  
  35.         Else
  36.             Console.WriteLine("Source file must have a .cs or .vb extension")
  37.         End If
  38.  
  39.         If Not provider Is Nothing Then
  40.  
  41.             ' Format the executable file name.
  42.             ' Build the output assembly path using the current directory
  43.             ' and <source>_cs.exe or <source>_vb.exe.
  44.  
  45.             Dim exeName As String = String.Format("{0}\{1}.exe", _
  46.                 System.Environment.CurrentDirectory, _
  47.                 sourceFile.Name.Replace(".", "_"))
  48.  
  49.             Dim cp As CompilerParameters = New CompilerParameters()
  50.  
  51.             ' Generate an executable instead of
  52.             ' a class library.
  53.             cp.GenerateExecutable = True
  54.  
  55.             ' Specify the assembly file name to generate.
  56.             cp.OutputAssembly = exeName
  57.  
  58.             ' Save the assembly as a physical file.
  59.             cp.GenerateInMemory = False
  60.  
  61.             ' Set whether to treat all warnings as errors.
  62.             cp.TreatWarningsAsErrors = False
  63.  
  64.             ' Invoke compilation of the source file.
  65.             Dim cr As CompilerResults = provider.CompileAssemblyFromFile(cp, _
  66.                 sourceName)
  67.  
  68.             If cr.Errors.Count > 0 Then
  69.                 ' Display compilation errors.
  70.                 Console.WriteLine("Errors building {0} into {1}", _
  71.                     sourceName, cr.PathToAssembly)
  72.  
  73.                 Dim ce As CompilerError
  74.                 For Each ce In cr.Errors
  75.                     Console.WriteLine("  {0}", ce.ToString())
  76.                     Console.WriteLine()
  77.                 Next ce
  78.             Else
  79.                 ' Display a successful compilation message.
  80.                 Console.WriteLine("Source {0} built into {1} successfully.", _
  81.                     sourceName, cr.PathToAssembly)
  82.             End If
  83.  
  84.             ' Return the results of the compilation.
  85.             If cr.Errors.Count > 0 Then
  86.                 compileOk = False
  87.             Else
  88.                 compileOk = True
  89.             End If
  90.         End If
  91.         Return compileOk
  92.  
  93.  
  94.     End Function
  95.  
  96. End Class


Thanks for looking!

Chris