Seqfilewrite1

 

Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click

'Dim seqfile As IO.StreamWriter = IO.File.CreateText("a:/colors.txt")

Dim seqfile As System.IO.StreamWriter

seqfile = System.IO.File.CreateText("a:/colors.txt")

With seqfile

.WriteLine("Red")

.WriteLine("Orange")

.WriteLine("Yellow")

.WriteLine("Green")

.WriteLine("Blue")

.WriteLine("Indigo")

.WriteLine("Violet")

.Close()

End With

End Sub

 

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click

'Dim seqfile As IO.StreamReader = IO.File.OpenText("a:/colors.txt")

Dim seqfile As System.IO.StreamReader

seqfile = System.IO.File.OpenText("a:/colors.txt")

Dim pt As Integer

For pt = 1 To 7

lstSeq.Items.Add(seqfile.ReadLine)

Next

seqfile.Close()

End Sub

 

Dept

 

Public Structure Dept

Dim DeptNo As Integer

Dim DeptNam As String

Dim DeptMang As String

Dim DeptBudg As Decimal

End Structure

Dim arrDept(3) As Dept

 

Private Sub btnInputDeptData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputDeptData.Click

For i = 1 To 4

arrDept(i - 1).DeptNo = CInt(InputBox("Enter Dept No", "Dept#"))

arrDept(i - 1).DeptNam = InputBox("Enter Dept Name", "Name")

arrDept(i - 1).DeptMang = InputBox("Enter Manager", "Manager")

arrDept(i - 1).DeptBudg = CDec(InputBox("Enter Budget", "Budget"))

Next

End Sub

 

Private Sub btnShowInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowInfo.Click

Dim intDept As Integer

'For i = 1 To 4

'intDept = i - 1

'lstDept.Items.Add(arrDept(intDept).DeptNo & " " & _

' arrDept(intDept).DeptNam & " " & _

' arrDept(intDept).DeptMang & " " & _

' arrDept(intDept).DeptBudg)

'Next

For i = 1 To 4

intDept = i - 1

With arrDept(intDept)

lstDept.Items.Add(.DeptNo & " " & .DeptNam & " " & _

.DeptMang & " " & .DeptBudg)

End With

Next

End Sub

 

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

i = 0

txtName.Text = ""

Do

If CInt(txtDept.Text) = arrDept(i).DeptNo Then

txtName.Text = arrDept(i).DeptNam

End If

i += 1

Loop Until txtName.Text <> "" Or i = 4

If txtName.Text = "" Then

txtName.Text = "Invalid"

End If

End Sub

End Class

 

Deptsub

 

Public Structure Dept

Dim DeptNo As Integer

Dim DeptNam As String

Dim DeptMang As String

Dim DeptBudg As Decimal

End Structure

Dim arrDept(3) As Dept

 

Private Sub btnInputDeptData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputDeptData.Click

For i = 1 To 4

arrDept(i - 1).DeptNo = CInt(InputBox("Enter Dept No", "Dept#"))

arrDept(i - 1).DeptNam = InputBox("Enter Dept Name", "Name")

arrDept(i - 1).DeptMang = InputBox("Enter Manager", "Manager")

arrDept(i - 1).DeptBudg = CDec(InputBox("Enter Budget", "Budget"))

Next

End Sub

 

Private Sub btnShowInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowInfo.Click

Dim intDept As Integer

'For i = 1 To 4

'intDept = i - 1

'lstDept.Items.Add(arrDept(intDept).DeptNo & " " & _

' arrDept(intDept).DeptNam & " " & _

' arrDept(intDept).DeptMang & " " & _

' arrDept(intDept).DeptBudg)

'Next

For i = 1 To 4

intDept = i - 1

With arrDept(intDept)

lstDept.Items.Add(.DeptNo & " " & .DeptNam & " " & _

.DeptMang & " " & .DeptBudg)

End With

Next

End Sub

 

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

i = 0

txtName.Text = ""

Do

If CInt(txtDept.Text) = arrDept(i).DeptNo Then

txtName.Text = arrDept(i).DeptNam

txtMang.Text = arrDept(i).DeptMang

txtBudg.Text = arrDept(i).DeptBudg

Else

i += 1

End If

Loop Until txtName.Text <> "" Or i = 4

If txtName.Text = "" Then

txtName.Text = "Invalid"

End If

End Sub

 

Private Sub btnBudgSub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBudgSub.Click

If txtName.Text <> "Invalid" Then

arrDept(i).DeptBudg = arrDept(i).DeptBudg - txtAmtSub.Text

lblBudgAfter.text = arrDept(i).DeptBudg

Else

txtAmtSub.Text = 0

lblBudgAfter.Text = "Search Failed"

End If

End Sub

End Class

 

Deptwrite

 

Public Structure Dept

Dim DeptNo As Integer

Dim DeptNam As String

Dim DeptMang As String

Dim DeptBudg As Decimal

End Structure

Dim arrDept(3) As Dept

 

Private Sub btnInputDeptData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputDeptData.Click

For i = 1 To 4

arrDept(i - 1).DeptNo = CInt(InputBox("Enter Dept No", "Dept#"))

arrDept(i - 1).DeptNam = InputBox("Enter Dept Name", "Name")

arrDept(i - 1).DeptMang = InputBox("Enter Manager", "Manager")

arrDept(i - 1).DeptBudg = CDec(InputBox("Enter Budget", "Budget"))

Next

End Sub

 

Private Sub btnShowInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowInfo.Click

Dim intDept As Integer

'For i = 1 To 4

'intDept = i - 1

'lstDept.Items.Add(arrDept(intDept).DeptNo & " " & _

' arrDept(intDept).DeptNam & " " & _

' arrDept(intDept).DeptMang & " " & _

' arrDept(intDept).DeptBudg)

'Next

For i = 1 To 4

intDept = i - 1

With arrDept(intDept)

lstDept.Items.Add(.DeptNo & " " & .DeptNam & " " & _

.DeptMang & " " & .DeptBudg)

End With

Next

End Sub

 

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

i = 0

txtName.Text = ""

Do

If CInt(txtDept.Text) = arrDept(i).DeptNo Then

txtName.Text = arrDept(i).DeptNam

txtMang.Text = arrDept(i).DeptMang

txtBudg.Text = arrDept(i).DeptBudg

Else

i += 1

End If

Loop Until txtName.Text <> "" Or i = 4

If txtName.Text = "" Then

txtName.Text = "Invalid"

End If

End Sub

 

Private Sub btnBudgSub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBudgSub.Click

If txtName.Text <> "Invalid" Then

arrDept(i).DeptBudg = arrDept(i).DeptBudg - txtAmtSub.Text

lblBudgAfter.Text = arrDept(i).DeptBudg

Else

txtAmtSub.Text = 0

lblBudgAfter.Text = "Search Failed"

End If

End Sub

 

Private Sub btnWriteArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteArray.Click

Dim w As Integer

Dim deptfile As IO.StreamWriter = IO.File.CreateText("a:/dept.txt")

For w = 0 To 3

With deptfile

.WriteLine(arrDept(w).DeptNo & arrDept(w).DeptNam & arrDept(w).DeptMang & arrDept(w).DeptBudg)

End With

Next

deptfile.Close()

End Sub

 

Private Sub btnWrite2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite2.Click

Dim w As Integer

FileOpen(1, "a:/deptfld2.txt", OpenMode.Output)

Dim fld1 As Integer, fld2 As String, fld3 As String, fld4 As Decimal

For w = 0 To 3

fld1 = arrDept(w).DeptNo

fld2 = arrDept(w).DeptNam

fld3 = arrDept(w).DeptMang

fld4 = arrDept(w).DeptBudg

WriteLine(1, fld1, fld2, fld3, fld4)

Next

FileClose(1)

End Sub

 

Private Sub btnWrite3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite3.Click

Dim w As Integer

Dim currpath As String

currpath = System.Environment.CurrentDirectory

FileOpen(1, currpath & "/deptfld3.txt", OpenMode.Output)

Dim fld1 As Integer, fld2 As String, fld3 As String, fld4 As Decimal

For w = 0 To 3

fld1 = arrDept(w).DeptNo

fld2 = arrDept(w).DeptNam

fld3 = arrDept(w).DeptMang

fld4 = arrDept(w).DeptBudg

Write(1, fld1, fld2, fld3, fld4)

Next

FileClose(1)

End Sub

End Class

 

Deptread

 

Private Sub btnRead1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead1.Click

Dim w As Integer

Dim currpath As String

currpath = System.Environment.CurrentDirectory

FileOpen(1, currpath & "/dept.txt", OpenMode.Input)

Dim fld1 As Integer, fld2 As String, fld3 As String, fld4 As Decimal

Dim fldwhole As String, flddisp As String

For w = 0 To 3

Input(1, fldwhole)

MsgBox(fldwhole)

fld1 = fldwhole.Substring(0, 2)

fld2 = fldwhole.Substring(2, 2)

fld3 = fldwhole.Substring(4, 2)

fld4 = fldwhole.Substring(6, 4)

flddisp = fld1 & " " & fld2 & " " & fld3 & " " & fld4

lstDept.Items.Add(flddisp)

Next

FileClose(1)

End Sub

 

Private Sub btnRead2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead2.Click

Dim stread As IO.StreamReader = IO.File.OpenText("a:/dept.txt")

Dim fld1 As String, fld2 As String, fld3 As String, fld4 As String

Dim fldwhole As String, flddisp As String

Dim w As Integer

Do While stread.Peek <> -1

fldwhole = stread.ReadLine

fld1 = fldwhole.Substring(0, 2)

MsgBox(fld1)

fld2 = fldwhole.Substring(2, 2)

MsgBox(fld2)

fld3 = fldwhole.Substring(4, 2)

MsgBox(fld3)

fld4 = fldwhole.Substring(6, 4)

MsgBox(fld4)

flddisp = fld1 & " " & fld2 & " " & fld3 & " " & fld4

lstDept.Items.Add(flddisp)

Loop

stread.Close()

End Sub

End Class