Week 4 and 5 and Week 10 = Resources
Coded in the WRITE Button
"WE PUT A TRY HERE SO THAT WE CAN CATCH AN EXCEPTION WHEN IT OCCURS"
Try
"IF STATMENT BEGINS"
If IO .File.Exists("Numbers.txt") Then
"DECLARE A STRING FOR MYNUMBERS WITH AN UPPERBOUND OF 4 AS IN THE ARRAY THERE ARE 5 ITEMS BUT AN ARRAY BEGINS FROM 0"
Dim MyNumbers (4) As String
"DECLARE THE STREAMREADER WHICH IS GOING TO READ OUR FILE NUMBERS.TXT"
Dim inFile As IO.StreamReader
inFile=IO.File.OpenText("Numbers.txt")
Dim intCount As Integer = 0
While InFile.Peek<>-1
MyNumbers(intcount)=inFile.ReadLine
inCount +=1
End While
inFile.Close()
Else
"A MESSAGE BOX WILL APPEAR SAYING FILE DOES NOT EXIST IF THE FILE CANNOT BE FOUND
MsgBox("File does not exist")
"WE END OUR END IF STATMENT"
End If
"HERE WE CATCH OUR EXCEPTION"
Catch AnyTypeOfException As Exception
"OUR MESSAGE BOX THAT APPEARS WHEN SOMETHING GOES WRONG AND
MsgBox("Sorry,something went wrong!")
"HERE WE END OUR TRY STATEMENT"
End Try
________________________________________
Try
If IO.File.Exists ("Numbers.txt")Then
Dim Outfile As IO.StreamWriter
outfile=IO.File.AppendText("Number.txt")
For intCount = 0 to MyNumbers.Length - 1
outfile.WriteLine(MyNumbers(intCount))
Next
outfile.Close()
Else
MsgBox("File Not Found!")
End If
Catch AnyTpyeOfException As Exception
End Try
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment