Compile and execute code on the fly…

A simple way to compile and execute code on the fly. From the cmd console:

notepad code.vb

This opens notepad with a new file called code.vb

Paste in a piece of code, for example:

Imports SystemImports
System.TextImports
System.SecurityImports
System.Security.CryptographyModule
App
Sub Main(ByVal argv() As String)

Dim len As Integer = 128

If argv.Length > 0 Then
len = Integer.Parse(argv(0))
End If

Dim buff(len / 2) As Byte
Dim rng As New RNGCryptoServiceProvider()

rng.GetBytes(buff)

Dim sb As New StringBuilder(len)
Dim i As Integer

For i = 0 To buff.Length - 1
sb.Append(String.Format("{0:X2}", buff(i)))
Next i

Console.WriteLine(sb)
Console.ReadLine()

End Sub 'MainEnd Module

Then save and close notepad.

Compile the code:

vbc code.vb

Execute the code:

code 128
code 64

Voila!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

A WordPress.com Website.

Up ↑

%d bloggers like this: