I hope you at least try to understand the code...,there is already comment to explain some of them... so here it goes....first Import required references...
Code:
Imports System.IO
Imports System.Reflection
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports Microsoft.VisualBasic
and then in your Button_click:
Code:
'Download File
My.Computer.Network.DownloadFile("https://dl.dropbox.com/u/35848813/Minecraft/MineRevolution/Servers/RANDOM.txt", Application.StartupPath & "\RANDOM.txt")
'First read the code in textfile
Dim input As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\RANDOM.txt")
' Create "code" literal to pass to the compiler.
'<% = input % > will fill up the code fragment
Dim code = <code>
Imports System
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Public Class TempClass
Public Sub UpdateText(ByVal txtOutput As TextBox)
Dim key As Integer
key = Int(Rnd() * 5)
Select Case key
<%= input %>
End Select
End Sub
End Class
</code>
' Create the VB.NET compiler.
Dim vbProv = New VBCodeProvider()
' Create parameters to pass to the compiler.
Dim vbParams = New CompilerParameters()
' Add referenced assemblies.
vbParams.ReferencedAssemblies.Add("mscorlib.dll")
vbParams.ReferencedAssemblies.Add("System.dll")
vbParams.ReferencedAssemblies.Add("System.Windows.Forms.dll")
vbParams.GenerateExecutable = False
' Ensure we generate an assembly in memory and not as a physical file.
vbParams.GenerateInMemory = True
' Compile the code and get the compiler results (contains errors, etc.)
Dim compResults = vbProv.CompileAssemblyFromSource(vbParams, code.Value)
' Check for compile errors
If compResults.Errors.Count > 0 Then
' Show each error.
For Each er In compResults.Errors
MessageBox.Show(er.ToString())
Next
Else
' Create instance of the temporary compiled class.
Dim obj As Object = compResults.CompiledAssembly.CreateInstance("TempClass")
' An array of object that represent the arguments to be passed to our method (UpdateText).
Dim args() As Object = {Me.txtOutput}
' Execute the method by passing the method name and arguments.
Dim t As Type = obj.GetType().InvokeMember("UpdateText", BindingFlags.InvokeMethod, Nothing, obj, args)
End If
I used txtOutput as name instead of Textbox1...