Monday, December 28, 2009

Writing and Compiling in Visual Basic

To compile use the command below

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe code.vb

Sample 1 (Console)
--------
Module Tester

Sub Main()
Console.Write("Welcome to ")
Console.WriteLine("Visual Basic!")
End Sub ' Main

End Module


Sample 2 (GUI)
--------
Imports System
Imports System.Windows.Forms

Class MyFirstForm
Inherits Form

Private WithEvents mybutton As Button

Public Sub New()
Me.Text = "Hello, WinForms!"
mybutton = New Button()
mybutton.Text = "Click Me!"
Me.Controls.Add(mybutton)
End Sub

Public Sub mybutton_Click(sender As Object, e As EventArgs) Handles mybutton.Click
MessageBox.Show("Message")
End Sub

End Class

Class MyFirstApp
Shared Sub Main()
Dim myform As Form = New MyFirstForm()
Application.Run(myform)
End Sub
End Class

No comments: