Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Public Class Form1
- 'Class level variables
- Private strFileName As String = String.Empty 'Documnent FIlename
- Dim blnIsChanged As Boolean = False
- ' Arrays to store the data
- Dim strStudents(5) As String
- Dim dblTestScores(5, 4) As Double
- Dim dblTestAvg(5) As Double
- Sub ClearDocuments()
- 'clear the test averages
- txtAvg1.Clear()
- txtAvg2.Clear()
- txtAvg3.Clear()
- txtAvg4.Clear()
- txtAvg5.Clear()
- txtAvg6.Clear()
- 'clear the student names
- txtName1.Clear()
- txtName2.Clear()
- txtName3.Clear()
- txtName4.Clear()
- txtName5.Clear()
- txtName6.Clear()
- 'clear the test scores
- txtScore1_1.Clear()
- txtScore1_2.Clear()
- txtScore1_3.Clear()
- txtScore1_4.Clear()
- txtScore1_5.Clear()
- txtScore2_1.Clear()
- txtScore2_2.Clear()
- txtScore2_3.Clear()
- txtScore2_4.Clear()
- txtScore2_5.Clear()
- txtScore3_1.Clear()
- txtScore3_2.Clear()
- txtScore3_3.Clear()
- txtScore3_4.Clear()
- txtScore3_5.Clear()
- txtScore4_1.Clear()
- txtScore4_2.Clear()
- txtScore4_3.Clear()
- txtScore4_4.Clear()
- txtScore4_5.Clear()
- txtScore5_1.Clear()
- txtScore5_2.Clear()
- txtScore5_3.Clear()
- txtScore5_4.Clear()
- txtScore5_5.Clear()
- txtScore6_1.Clear()
- txtScore6_2.Clear()
- txtScore6_3.Clear()
- txtScore6_4.Clear()
- txtScore6_5.Clear()
- 'Clear document name
- strFileName = String.Empty
- 'Set blnIsChanged to false
- blnIsChanged = False
- End Sub
- Sub OpenDocument()
- Dim inputFile As StreamReader
- If ofdOpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then
- ' Retrieve the selected filename
- strFileName = ofdOpenFile.FileName
- Try
- ' Open the file
- inputFile = File.OpenText(strFileName)
- 'Read the files contents into the textboxes
- ' Close the file
- inputFile.Close()
- ' Update the is changed variable.
- blnIsChanged = False
- Catch
- ' Error message for file open erros
- MessageBox.Show("Error opening the file.")
- End Try
- End If
- End Sub
- ' The SaveData() function saves the data to a text file
- Sub SaveData()
- ' Take the info from the text boxes and store them into the arrays
- strStudents(0) = txtName1.Text
- strStudents(1) = txtName2.Text
- strStudents(2) = txtName3.Text
- strStudents(3) = txtName4.Text
- strStudents(4) = txtName5.Text
- strStudents(5) = txtName6.Text
- dblTestScores(0, 0) = txtScore1_1.Text
- dblTestScores(0, 1) = txtScore1_2.Text
- dblTestScores(0, 2) = txtScore1_3.Text
- dblTestScores(0, 3) = txtScore1_4.Text
- dblTestScores(0, 4) = txtScore1_5.Text
- dblTestScores(1, 0) = txtScore2_1.Text
- dblTestScores(1, 1) = txtScore2_2.Text
- dblTestScores(1, 2) = txtScore2_3.Text
- dblTestScores(1, 3) = txtScore2_4.Text
- dblTestScores(1, 4) = txtScore2_5.Text
- dblTestScores(2, 0) = txtScore3_1.Text
- dblTestScores(2, 1) = txtScore3_2.Text
- dblTestScores(2, 2) = txtScore3_3.Text
- dblTestScores(2, 3) = txtScore3_4.Text
- dblTestScores(2, 4) = txtScore3_5.Text
- dblTestScores(3, 0) = txtScore4_1.Text
- dblTestScores(3, 1) = txtScore4_2.Text
- dblTestScores(3, 2) = txtScore4_3.Text
- dblTestScores(3, 3) = txtScore4_4.Text
- dblTestScores(3, 4) = txtScore4_5.Text
- dblTestScores(4, 0) = txtScore5_1.Text
- dblTestScores(4, 1) = txtScore5_2.Text
- dblTestScores(4, 2) = txtScore5_3.Text
- dblTestScores(4, 3) = txtScore5_4.Text
- dblTestScores(4, 4) = txtScore5_5.Text
- dblTestScores(5, 0) = txtScore6_1.Text
- dblTestScores(5, 1) = txtScore6_2.Text
- dblTestScores(5, 2) = txtScore6_3.Text
- dblTestScores(5, 3) = txtScore6_4.Text
- dblTestScores(5, 4) = txtScore6_5.Text
- Dim outputFile As StreamWriter
- Try
- ' Create the file.
- outputFile = File.CreateText(strFileName)
- ' Write the contents of the arrays to the text file
- For intCount = 0 To (strStudents.Length - 1)
- outputFile.WriteLine(strStudents(intCount))
- For intCount1 = 0 To (dblTestScores.Length - 1)
- outputFile.WriteLine(dblTestScores(intCount1, intCount1))
- Next
- Next
- ' Close the file
- outputFile.Close()
- Catch
- MessageBox.Show("Error saving the file.")
- End Try
- End Sub
- Private Sub menuSave_Click(sender As Object, e As EventArgs) Handles menuSave.Click
- ' Does the current document have a filename?
- If strFileName = String.Empty Then
- ' The data has not been saved, so use the save as dialog box.
- If sfdSaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
- strFileName = sfdSaveFile.FileName
- SaveData()
- End If
- Else
- ' Save the document with the current filename
- SaveData()
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement