' Form to enter data
' Created 2011
' ByDMBoudreau
PublicClassfrmDataEntry
PrivateSubtsmHelp_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlestsmHelp.Click
' displays inline help (form) from menu strip Help item
frmhelp.Show()
EndSub
PrivateSubcmdClose_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlescmdClose.Click
' close data entry window, ask first, but don't exit program
closeDataEntry()
EndSub
PrivateSubtsmSearchData_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) HandlestsmSearchData.Click
' display the search data window
frmSearch.Show()
EndSub
PrivateSubtsmMainMenu_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlestsmMainMenu.Click
' Closes this Data entry window
DimintReplyAsInteger
intReply = MsgBox("Did you remember to save your data, if you entered data, before closing this program?", vbYesNo + vbExclamation, "Save Data Before Exiting")
IfintReply = 6 Then
Me.Close()
EndIf
EndSub
PrivateSubcmdEnter_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) HandlescmdEnter.Click
' enters data
cmdEnterData()
EndSub
PrivateSubtsmEnterData_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlestsmEnterData.Click
' enters data
cmdEnterData()
EndSub
PrivateSubtsmSaveData_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) HandlestsmSaveData.Click
' saves data
' calls from sub cmdSaveData() to run code
cmdSaveData()
EndSub
SubcmdEnterData()
' create a variable course name
DimstrCourseNameAsString = ""
' if radio button VB is checked then Course Name equals the text Visual Basic
IfradVB.CheckedThen
strCourseName = "Visual Basic"
EndIf
' if radio button DB is checked then Course Name equals the text DataBase
IfradDB.CheckedThen
strCourseName = "DataBase"
EndIf
' if radio button FND is checked then Course Name equals the text Foundations
IfradFND.CheckedThen
strCourseName = "Foundations"
EndIf
' check if anything was entered into the two text boxes
IftxtFName.TexttxtLName.TexttxtMark.Text""Then
' check if the mark text box is a number if it is then enter the data
IfIsNumeric(txtMark.Text) = TrueThen
' select as number what's in the text box
SelectCaseCInt(txtMark.Text)
' which is from 0 to 100
Case 0 To 100
' if the text in the first name textbox is great or less then nothing
IftxtFName.Text""Then
' add the contents of first and last name textboxes together into the listbox
lstboxData.Items.Add(txtFName.Text" "txtLName.Text" ")
' then add the contents of the coursename textbox to the listbox
lstboxData.Items.Add(strCourseName)
' then add the contents of the mark text box to the listbox
lstboxData.Items.Add(CInt(txtMark.Text))
' check if numbers have been entered into the text boxes
IfIsNumeric(txtFName.TexttxtLName.Text) = TrueThen
' if numbers have been entered display a message
MsgBox("You can not enter a number into the name text boxes", vbExclamation)
EndIf
' if the mark text box is not a number then display messagebox
Else
MsgBox("You either missed entering one or both names. Please enter a name to continue.",vbExclamation)
EndIf
' in the case of the number being above 100 then display message
CaseIs > 100
MsgBox("Number is too high")
' in the case of the number being below 0 then display a message
CaseIs < 0
MsgBox("Number is too low")
EndSelect
Else
' display a messagebox if a mark/number was not entered
MsgBox("you did not enter a mark", vbExclamation)
EndIf
' if the mark text box does not equal a number display a messagebox
ElseIftxtMark.Text = ""Then
MsgBox("You did not enter anything", vbExclamation)
EndIf
' clear all the textboxes if data is or is not entered
txtFName.Text = ""
txtLName.Text = ""
txtMark.Text = ""
EndSub
PrivateSubcmdSave_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlescmdSave.Click
' makes a call to the sub cmdSaveData to do the work
cmdSaveData()
EndSub
SubcmdSaveData()
' save data to a file using a Stream Writer
' create the Stream Writer and variable
DimswrWritetoFileAsSystem.IO.StreamWriter
' assignafile name to the variable
swrWritetoFile = System.IO.File.AppendText("c:\VBFinal\IT1_Names.txt")
' create variable for the count
DimintCountAsInteger
' create variable for loop
DimintloopAsInteger
' assign value to variable
intCount = lstboxData.Items.Count
' create loop to run for number of items in listbox
Forintloop = 0 TointCount - 1
' Write the item at the loop position to the file
swrWritetoFile.WriteLine(lstboxData.Items.Item(intloop))
' continue loop again
Nextintloop
' close writer
swrWritetoFile.Close()
MsgBox(intCount" entries has been written to file")
' clears the listbox when saving data to file
lstboxData.Items.Clear()
EndSub
SubcloseDataEntry()
' end program but ask if data saved first
' use the plus symbol to join two values together into the messagebox
' ie. yesno buttons and exclamation icon
DimintReplyAsInteger
intReply = MsgBox("Did you remember to save your data, if you entered data, before closing this program?", vbYesNo + vbExclamation, "Save Data Before Exiting")
IfintReply = 6 Then
End
EndIf
EndSub
PrivateSubcmdClear_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlescmdClear.Click
' clears the listbox
lstboxData.Items.Clear()
EndSub
EndClass