I have Two Text Boxes where the user enters their name. I need to validate that the boxes are not left empty and also no numeric data is entered. If it either is entered the click event Cost will determine invalid values and display message box error. Obviously my problem is in red. I keep getting an “Invalid Cast Exception Conversion to string dd to type long is not valid” Also; I know the syntax to test for Numeric data…but how do you test for and empty textbox (string) and to make sure it is alphabetical data? And are my code tags correct?
Public Class Form1
Private Sub btnCalcCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcCost.Click
Dim numMonths As Integer
Dim decTotalCost As Decimal
Dim memCost As Integer
Dim singleMem As Decimal = 38D
Dim FamilyMem As Decimal = 58D
Dim seniorMem As Decimal = 27D
If IsNumeric(Me.txtNumberOfMon.Text) Then numMonths = Convert.ToInt16(Me.txtNumberOfMon.Text)
If IsNumeric(Me.txtFirstName.Text Or Me.txtLastName.Text) Then
ElseIf (strLastName Or strFirstName) = "" Then
MessageBox.Show("Error")
If numMonths > 0 Then
If Me.radSingleMem.Checked Then
memCost = singleMem
ElseIf Me.radFamilyMem.Checked Then
memCost = FamilyMem
ElseIf Me.radSeniorMem.Checked Then
memCost = seniorMem
End If
decTotalCost = numMonths * memCost
Me.lblTotalCost.Text = decTotalCost.ToString("c")
Else
MessageBox.Show("You entered non-numeric number or " _
& numMonths.ToString() & _
". Enter number greater than zero.")
Me.txtNumberOfMon.Text = ""
Me.txtNumberOfMon.Focus()
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
Me.txtNumberOfMon.Clear()
Me.txtFirstName.Clear()
Me.txtLastName.Clear()
Me.lblTotalCost.Text = ""
Me.radSingleMem.Checked = False
Me.radFamilyMem.Checked = False
Me.radSeniorMem.Checked = False
End Sub
End Class