geeroc
Joined: 11 Jun 2008 Posts: 1
|
Posted: Wed Jun 11, 2008 5:40 am Post subject: vb 2008 error Conversion from string "" to type 'I |
|
|
when ever I click my submit button and submit empty fields my program crashes and i get InvalidCastException was unhandled error//Conversion from string "" to type 'Integer' is not valid. thats the only problem i have everyhting else works fine.
can anyone help with my problem i put in bold the problem areas i beleive are at the core of it crashing.
here is my code.
Public Class Form1
Dim dgrResultExit As DialogResult
Dim strMessageExit As String
Dim strInputCode As String
Dim strInputCredits As String
Dim strInputDependents As String
Dim intCredits As Integer
Dim intDependents As Integer
Dim intCode As Integer
Dim intAmount As Integer
Dim strStudentName As String
Dim strStatus As String
Dim intTotalFinancialAssistance As Integer = 0
Dim intTotalPartTimeVeteranStudents As Integer = 0
Dim intTotalFullTimeVeteranStudents As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'****************
'*PRINT HEADINGS*
'****************
Form2.txtOutput.Text = Form2.txtOutput.Text & ControlChars.NewLine & ("Name" & Space(10) & "Credits" & Space(8) & "Dependents" & Space(10) & "Amount")
End Sub
Private Sub GetRecord()
'**************************************************
'*retreive submited scores and stores in variables*
'**************************************************
strStudentName = CStr(txtStudentName.Text)
intCredits = CInt(txtCredits.Text)
intDependents = CInt(txtDependents.Text)
intCode = CInt(txtCode.Text)
End Sub
Private Sub ToolTip1_Popup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PopupEventArgs) Handles ToolTip1.Popup
End Sub
'***********************************************
'*Clears all text boxes when btnClear activated*
'***********************************************
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
txtStudentName.Clear()
txtCode.Clear()
txtCredits.Clear()
txtDependents.Clear()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
strMessageExit = "All information will be lost, are you sure you want to exit the program?"
dgrResultExit = MessageBox.Show(strMessageExit, "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If dgrResultExit = DialogResult.Yes Then
End If
End
End Sub
Private Sub btnClearStudentName_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearStudentName.Click
txtStudentName.Clear()
txtStudentName.Focus()
End Sub
Private Sub btnClearCode_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearCode.Click
txtCode.Clear()
txtCode.Focus()
End Sub
Private Sub btnClearCredits_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearCredits.Click
txtCredits.Clear()
txtCredits.Focus()
End Sub
Private Sub btnClearDependents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearDependents.Click
txtDependents.Clear()
txtDependents.Focus()
End Sub
'*************
'*CALCULATION*
'*************
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Call GetRecord()
If intCode = 2 Then
If intCredits < 15 Then
If intDependents < 2 Then
intAmount = 20 * intCredits
Else
intAmount = 23 * intCredits
End If
strStatus = "Part-Time"
intTotalPartTimeVeteranStudents = intTotalPartTimeVeteranStudents + 1
Else
If intDependents < 2 Then
intAmount = 27 * intCredits
Else
intAmount = 30 * intCredits
End If
strStatus = "Full-Time"
intTotalFullTimeVeteranStudents = intTotalFullTimeVeteranStudents + 1
End If
intTotalFinancialAssistance = intTotalFinancialAssistance + intAmount
Form2.txtOutput.Text = Form2.txtOutput.Text & ControlChars.NewLine & (strStudentName & Space(9) & intCredits.ToString & Space(18) & intDependents.ToString & Space(16) & intAmount.ToString("C"))
End If
'*************************
'* INPUT FIELDS CLEARED *
'*************************
txtCode.Clear()
txtStudentName.Clear()
txtCredits.Clear()
txtDependents.Clear()
txtStudentName.Focus()
End Sub
'*********************************************************************************************************
'*Prints Total Full-Time Students, Total Part-Time Students and Total Financial Assistance to output form*
'*********************************************************************************************************
Private Sub btnCreateAReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateAReport.Click
Form2.txtOutput.Text = Form2.txtOutput.Text & ControlChars.NewLine & ("")
Form2.txtOutput.Text = Form2.txtOutput.Text & ControlChars.NewLine & ("Total Full-Time Students: " & intTotalFullTimeVeteranStudents)
Form2.txtOutput.Text = Form2.txtOutput.Text & ControlChars.NewLine & ("Total Part-Time Students: " & intTotalPartTimeVeteranStudents)
Form2.txtOutput.Text = Form2.txtOutput.Text & ControlChars.NewLine & ("Total Financial Assistance: " & intTotalFinancialAssistance.ToString("C"))
Form2.Show()
Me.Hide()
End Sub
'****************************
'*Validation of each textbox*
'****************************
'Private Sub txtStudentName_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStudentName.TextChanged
' If txtStudentName.Text = "" Or IsNumeric(txtStudentName.Text) Then
' strStudentName = "No numbers are allowed, please use Letters of the alphabet"
' dgrResultExit = MessageBox.Show(strStudentName, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
' txtStudentName.Clear()
' Else
' End If
'End Sub
Private Sub txtCode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCode.TextChanged
If Not IsNumeric(txtCode.Text) And txtCode.Text <> "" Then
strInputCode = "No letters are allowed or empty fields, please use numbers"
dgrResultExit = MessageBox.Show(strInputCode, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtCode.Clear()
End If
End Sub
Private Sub txtCredits_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCredits.TextChanged
If Not IsNumeric(txtCredits.Text) And txtCredits.Text <> "" Then
strInputCredits = "No letters are allowed or empty fields, please use numbers"
dgrResultExit = MessageBox.Show(strInputCredits, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtCredits.Clear()
End If
End Sub
Private Sub txtDependents_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDependents.TextChanged
If Not IsNumeric(txtDependents.Text) And txtDependents.Text <> "" Then
strInputDependents = "No letters are allowed or empty fields, please use numbers"
dgrResultExit = MessageBox.Show(strInputDependents, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtDependents.Clear()
End If
End Sub
End Class |
|