I´m beginner and trying build a Windows Phone App with vb.net. I want to validate empty textbox but once start app, this blocked and it shows the following exception error.This calculate fine if the fields are filled but if some field is empty appears the error.
El código de usuario no controló System.InvalidCastException
HResult=-2147467262
Message=Input string was not in a correct format.
Source=Conversionvbnet
StackTrace:
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
at Conversionvbnet.CourseGSWCA.calculatebtn_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
InnerException: System.FormatException
HResult=-2146233033
Message=Input string was not in a correct format.
Source=Conversionvbnet
StackTrace:
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
InnerException:
And it´s the code:
Private Sub calculatebtn_Click(sender As Object, e As RoutedEventArgs) Handles calculatebtn.Click
Dim windspeed As String = wsptxt.Text
Dim windirection As String = wdtxt.Text
Dim heading As String = headingtxt.Text
Dim speed As String = tastxt.Text
Dim valor As String = datosmsg.Text
If String.IsNullOrEmpty(wsptxt.Text.ToString()) Then
MessageBox.Show("Faltan datos")
ElseIf String.IsNullOrEmpty(wdtxt.Text.ToString()) Then
MessageBox.Show("Faltan datos")
ElseIf String.IsNullOrEmpty(headingtxt.Text.ToString()) Then
MessageBox.Show("Faltan datos")
ElseIf String.IsNullOrEmpty(tastxt.Text.ToString()) Then
MessageBox.Show("Faltan datos")
End If
datosmsg.Text = CStr(CInt(wsptxt.Text) + CInt(wdtxt.Text) + CInt(headingtxt.Text) + CInt(tastxt.Text))
I don´t know exactly what happen about this. I tried many ways and appear the same error.
Thanks in advance
Reg