You are on page 1of 18

1.

Grade callculator
coding
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Select Case Val(TextBox2.Text)
Case Is > 90
MsgBox(TextBox1.Text & " has got a+ grade")
Exit Sub
Case Is > 70
MsgBox(TextBox1.Text & " has got a grade")
Exit Sub
Case Is > 60
MsgBox(TextBox1.Text & " has got b grade")
Exit Sub
Case Is > 40
MsgBox(TextBox1.Text & " has got c grade")
Exit Sub
Case Is > 0
MsgBox(TextBox1.Text & " has got f grade")
Case Is < 0
MsgBox("marks cannot be negative")
End Select
End Sub
End Class

Design time

Run time

2. Callculator
coding
Public Class Form1
Dim flag As Boolean
Dim val1 As String
Dim opr As String
Sub disp()
Dim a, b As Double
a = Val(val1)
If Not TextBox1.Text = "" Then
b = Val(TextBox1.Text)
Else
b=0
End If
val1 = TextBox1.Text
Select Case opr
Case "+"
TextBox1.Text = a + b
Case "-"
TextBox1.Text = a - b
Case "*"
TextBox1.Text = a * b
Case "/"
TextBox1.Text = a / b
End Select
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.ReadOnly = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click,
Button10.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click,
Button8.Click, Button9.Click
If flag = True Then
val1 = TextBox1.Text
TextBox1.Text = ""
flag = False
End If
TextBox1.Text = TextBox1.Text & sender.text
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click, Button14.Click, Button15.Click,
Button16.Click
flag = True

If Not opr = "" Then


disp()
End If
opr = sender.text
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button12.Click
opr = ""
TextBox1.Text = ""
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button11.Click
If Not opr = "" Then
disp()
End If
opr = ""
flag = True
End Sub
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button17.Click
If flag = True Then
TextBox1.Text = ""
End If
If Not TextBox1.Text.Contains(sender.text) Then
TextBox1.Text = TextBox1.Text & sender.text
End If
flag = False
End Sub
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button18.Click
Dim d, f As String
f = ""
d = TextBox1.Text
Dim a() As Char = d.ToCharArray
For i = 0 To a.Count - 2
f = f & a(i)
Next
TextBox1.Text = f
End Sub
End Class

design time

Run time

3. Loan callculator

Coding
Public Class Form1
Dim p, r, t, i As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not IsNumeric(TextBox1.Text) Then
MsgBox("value of principal is outside the scope")
End If
If Not IsNumeric(TextBox2.Text) Then
MsgBox("value of rate is outside the scope")
End If
If Not IsNumeric(TextBox3.Text) Then
MsgBox("value of time outside the scope ")
End If
Try
p = Val(TextBox1.Text)
r = Val(TextBox2.Text)
t = Val(TextBox3.Text)
Catch ex As Exception
MsgBox("value of either principal, intrest of time isn't correct kindly
correct it and try againg")
End Try
i = p * r * t / 100
Label5.Text = i.ToString
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
End Class

Design time

Run time

4. Stop watch and collections

Coding
Public Class Form1
Dim day, hour, min, sec, msec, tch As Int16
Dim t As String = "touch"
Dim tc As New Collection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
msec = 0
tch = 1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
msec += 1
If msec > 9 Then
sec += 1
msec = 0
If sec > 59 Then
min += 1
sec = 0
If min > 59 Then
hour += 1
min = 0
If hour > 23 Then
day += 1
hour = 0
End If
End If
End If
End If
TextBox1.Text = day.ToString & ":" & hour.ToString & ":" & min.ToString &
":" & sec.ToString & ":" & msec.ToString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
msec = 0
sec = 0
min = 0
hour = 0
day = 0
Timer1.Start()
If Button1.Text = "start" Then
Button1.Text = "stop"
Else

Button1.Text = "start"
Timer1.Stop()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Button2.Text = "pause" Then
Timer1.Stop()
Button2.Text = "resume"
Else
Timer1.Start()
Button2.Text = "pause"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim key As String
key = t & tch.ToString
tc.Add(TextBox1.Text, key)
tch += 1
ComboBox1.Items.Add(key)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Label1.Text = tc.Item(ComboBox1.SelectedItem.ToString).ToString()
End Sub
End Class

design time

Run time

5. drawing in visual basic

coding
Public Class Form1
Dim g As Graphics
Dim start As Boolean
Dim shape As String
Dim x, y, nx, ny As Integer
Dim p As Pen
Dim bmp As Bitmap
Function widthr() As Integer
If (nx - x) < 0 Then
Return -(nx - x)
Else
Return (nx - x)
End If
End Function
Function heightr() As Integer
If (ny - y) < 0 Then
Return -(ny - y)
Else
Return (ny - y)
End If
End Function
Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
start = True
x = MousePosition.X
y = MousePosition.Y
End Sub
Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If start = True Then
nx = MousePosition.X
ny = MousePosition.Y
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
shape = "rectangle"
bmp = New Bitmap(Me.Width, Me.Height)
Me.BackgroundImage = bmp
ComboBox1.Items.Add(System.Drawing.Color.Red)
ComboBox1.Items.Add(System.Drawing.Color.Black)
ComboBox1.Items.Add(System.Drawing.Color.Blue)
ComboBox1.Items.Add(System.Drawing.Color.Brown)
p = Pens.Blue
g = Me.CreateGraphics
'g = Graphics.FromImage(bmp)

'g.Clear(Me.BackColor)
End Sub
Private Sub Form1_MouseUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
start = False
If shape = "line" Then
g.DrawLine(p, x, y, nx, ny)
End If
If shape = "rectangle" Then
g.DrawRectangle(p, x, y, widthr(), heightr())
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
p = New Pen(CType(ComboBox1.SelectedItem, System.Drawing.Color), 2)
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox2.SelectedIndexChanged
shape = ComboBox2.SelectedItem.ToString
End Sub
End Class

Design time

Run time

6. Notepad

Coding
Public Class Form1
Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click
Try
Clipboard.SetText(TextBox1.SelectedText)
TextBox1.SelectedText = ""
Catch ex As Exception
MsgBox("no text was selected")
End Try
End Sub
Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
If Clipboard.ContainsText Then
TextBox1.Paste(Clipboard.GetText)
Else
MsgBox("clipboard dosent contains any text")
End If
End Sub
Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
Try
Clipboard.SetText(TextBox1.SelectedText)
Catch ex As Exception
MsgBox("no text selected to copy")
End Try
End Sub
Private Sub DateToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DateToolStripMenuItem.Click
TextBox1.Paste(DateToolStripMenuItem.Text)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Clipboard.Clear()
End Sub
Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles
MenuStrip1.ItemClicked
DateToolStripMenuItem.Text = Now.Date
TimeToolStripMenuItem.Text = Now.Hour.ToString & ":" &

Now.Minute.ToString & ":" & Now.Second.ToString


End Sub
Private Sub TimeToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TimeToolStripMenuItem.Click
TextBox1.Paste(TimeToolStripMenuItem.Text)
End Sub
Private Sub SetToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles SetToolStripMenuItem.Click
End Sub
Private Sub ToolStripComboBox1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ToolStripComboBox1.Click
End Sub
End Class

Desing time

Run time

7. CODING OF MDIFORM
Private Sub MDIEXIT_Click()
Unload MDIForm1
End
End Sub
Private Sub MDINEW_Click()
Dim WINDEX As Integer
WINDEX = FindFree()
If WINDEX = -1 Then
MsgBox "u mst close doc before_another one cn be opened"
Exit Sub
End If
Load Documentforms(WINDEX)
Load Documentforms(WINDEX).Caption = "new doc"
Documentforms(WINDEX).Tag = WINDEX
Documentforms(WINDEX).Show
End
End Sub
Private Sub MDIOPEN_Click()
MDIForm1.MDIOPEN_Click
End Sub

You might also like