Public Class Form2
Dim emNum(50), emSal(50) As Double
Dim emName(50) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As IO.StreamReader = IO.File.OpenText("list.txt")
Dim cnt As Integer = 1
Dim line, fields(3) As String
Do While sr.Peek <> -1
line = sr.ReadLine
fields = line.Split(","c)
emNum(cnt) = CDbl(fields(0))
emName(cnt) = fields(1)
emSal(cnt) = CDbl(fields(2))
cnt += 1
Loop
sr.Close()
For i As Integer = 1 To cnt - 1
ListBox1.Items.Add(emName(i))
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
txtemNum.Text = emNum(ListBox1.SelectedIndex + 1)
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim sw As IO.StreamWriter = IO.File.AppendText("list.txt")
sw.WriteLine(txtemNum.Text & "," & txtemName.Text & "," & txtemSal.Text)
sw.Close()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim sr As IO.StreamReader = IO.File.OpenText("list.txt")
Dim sw As IO.StreamWriter = IO.File.CreateText("TEMP.txt")
Dim cnt As Integer = 1
Dim line, fields(3) As String
Do While (sr.Peek <> -1)
line = sr.ReadLine
fields = line.Split(","c)
emNum(cnt) = CDbl(fields(0))
emName(cnt) = fields(1)
emSal(cnt) = CDbl(fields(2))
If emName(cnt) <> emName(ListBox1.SelectedIndex + 1) Then
sw.WriteLine(emNum(cnt) & "," & emName(cnt) & "," & emSal(cnt))
End If
cnt += 1
Loop
sr.Close()
sw.Close()
IO.File.Delete("list.txt")
IO.File.Move("TEMP.txt", "list.txt")
End Sub
Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
Dim sr As IO.StreamReader = IO.File.OpenText("list.txt")
Dim sw As IO.StreamWriter = IO.File.CreateText("TEMP.txt")
Dim cnt As Integer = 1
Dim line, fields(3) As String
'emNum(ListBox1.SelectedIndex + 1) = ""
'emName(ListBox1.SelectedIndex + 1) = ""
'emSal(ListBox1.SelectedIndex + 1) = ""
Do While (sr.Peek <> -1)
line = sr.ReadLine
fields = line.Split(","c)
emNum(cnt) = CDbl(fields(0))
emName(cnt) = fields(1)
emSal(cnt) = CDbl(fields(2))
If emName(cnt) <> emName(ListBox1.SelectedIndex + 1) Then
sw.WriteLine(emNum(cnt) & "," & emName(cnt) & "," & emSal(cnt))
Else
sw.WriteLine(txtemNum.Text & "," & emName(cnt) & "," & txtemSal.Text)
End If
cnt += 1
Loop
sr.Close()
sw.Close()
IO.File.Delete("list.txt")
IO.File.Move("TEMP.txt", "list.txt")
End Sub
Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
Dim totalSal, totalMP, cnt As Double
Dim fmtStr As String = "{0,-15}{1,15}{2,15:C0}{3,15:C0}"
With ListBox2.Items
.Clear()
.Add(" Employee Salary report")
.Add("")
.Add(String.Format(fmtStr, "Employee #", "NAME", "SALARY", "MONTHLY PAY"))
.Add("")
For i As Integer = 1 To emNum.GetUpperBound(0)
totalMP += emSal(i) / 12
totalSal += emSal(i)
If emName(i) <> "" Then
cnt += 1
.Add(String.Format(fmtStr, emNum(i), emName(i), emSal(i), emSal(i) / 12))
End If
Next
.Add("")
.Add(String.Format(fmtStr, "TOTALS", " ", totalSal, totalMP))
.Add(String.Format(fmtStr, "AVERAGES", " ", totalSal / cnt, totalMP / cnt))
End With
End Sub
============================================================================================================
Public Class Form3
Dim univ(5) As String
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As IO.StreamReader = IO.File.OpenText("univ.txt")
For i As Integer = 1 To 5
univ(i) = sr.ReadLine
ComboBox1.Items.Add(univ(i))
Next
sr.Close()
ComboBox2.Items.Add("ITM 100")
ComboBox2.Items.Add("ITM 200")
ComboBox2.Items.Add("ITM 300")
ComboBox2.Items.Add("ITM 400")
ComboBox2.Items.Add("ITM 500")
ComboBox3.Items.Add("Freshmen")
ComboBox3.Items.Add("Sophmore")
ComboBox3.Items.Add("Junior")
ComboBox3.Items.Add("Seniour")
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Format(Now, "HH:mm:ss")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.CreateGraphics.DrawRectangle(Pens.Black, 25, 25, 50, 50)
PictureBox1.CreateGraphics.DrawEllipse(Pens.Blue, 55, 55, 50, 50)
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
TextBox1.Text = VScrollBar1.Value
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim opt As String
Dim team As String = ""
'RadioButton selection
If RadioButton1.Checked Then
opt = "Systems"
ElseIf RadioButton2.Checked Then
opt = "Telecommunications"
ElseIf RadioButton3.Checked Then
opt = "Management"
End If
'Checkbox selection
If CheckBox1.Checked Then
team += "Toronto Raptors" & vbCrLf
End If
If CheckBox2.Checked Then
team += "Toronto Maple Leafs" & vbCrLf
End If
If CheckBox3.Checked Then
team += "Toronto Argonauts" & vbCrLf
End If
If CheckBox4.Checked Then
team += "Toronto FC" & vbCrLf
End If
'Random Numbers
Dim numbers As String
Dim randomNum As New Random
Dim num1, num2, num3, num4, num5, num6 As Integer
num1 = randomNum.Next(0, 50)
num2 = randomNum.Next(0, 50)
num3 = randomNum.Next(0, 50)
num4 = randomNum.Next(0, 50)
num5 = randomNum.Next(0, 50)
num6 = randomNum.Next(0, 50)
numbers = "Random 6/49 numbers are : " & num1 & " " & num2 & " " & num3 & " " & num4 & " " & num5 & " " & num6
MsgBox("You chose: " & vbCrLf & ComboBox1.Text & vbCrLf & ComboBox2.Text & vbCrLf & ComboBox3.Text & vbCrLf & opt & vbCrLf & team & numbers)
End Sub
Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs)
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
MsgBox("You chose File - Open ")
End Sub
Private Sub OpenToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem2.Click
OpenFileDialog1.showDialog()
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
SaveFileDialog1.ShowDialog()
End Sub
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
FontDialog1.ShowDialog()
End Sub
Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
ColorDialog1.ShowDialog()
End Sub
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
PrintDialog1.ShowDialog()
End Sub
===================================================================================================================================
Public Class Form2
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim letter As String
Dim i, count As Integer
letter = InputBox("Enter a letter to search")
Do While i <= TextBox1.Text.Length - 1
If (TextBox1.Text.Substring(i, 1)).ToUpper = letter.ToUpper Then
count += 1
End If
i += 1
Loop
ListBox1.Items.Add("There are " & count & " " & letter.ToUpper & "'s in the sentence")
End Sub
========================================================================================================================================
Public Class Form3
Dim sname(100) As String, cnt As Integer
Dim reportDate As String
Dim westsales(100), centralsales(100), eastsales(100) As Double
Dim subtotal(100) As Double
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sr As IO.StreamReader = IO.File.OpenText("sales.txt")
Dim line, fields(3) As String
reportDate = sr.ReadLine
cnt = -1
Do While sr.Peek <> -1
cnt += 1
line = sr.ReadLine
fields = line.Split(","c)
sname(cnt) = fields(0)
westsales(cnt) = CDbl(fields(1))
centralsales(cnt) = CDbl(fields(2))
eastsales(cnt) = CDbl(fields(3))
subtotal(cnt) = westsales(cnt) + centralsales(cnt) + eastsales(cnt)
Loop
sr.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
Dim fmtStr As String = "{0,-15}{1,10:C0}{2,10:C0}{3,10:C0}{4,15:C0}"
Dim westsalestotal, centralsalestotal, eastsalestotal, subtotaltotal As Double
With ListBox1.Items
.Clear()
.Add(" SALES REPORT AS OF " & reportDate)
.Add("")
.Add(String.Format(fmtStr, " ", "WEST", "CENTRAL", "EAST", "TOTAL"))
Dim i As Integer
For i = 0 To sname.GetUpperBound(0)
If sname(i) <> "" Then
.Add(String.Format(fmtStr, sname(i), westsales(i), centralsales(i), eastsales(i), subtotal(i)))
westsalestotal += westsales(i)
centralsalestotal += centralsales(i)
eastsalestotal += eastsales(i)
subtotaltotal += subtotal(i)
End If
Next
.Add("")
.Add(String.Format(fmtStr, "TOTALS", westsalestotal, centralsalestotal, eastsalestotal, subtotaltotal))
End With
End Sub
================================================================================================================================