Principales respuestas
TENGO PROBLEMAS CON ESTA PARTE SUBRAYADA DEL CODIGO

Pregunta
-
TENGO PROBLEMAS CON ESTA PARTE DEL CODIGO, AL EJECUTAR EL FORMULARIO:
No se controló System.InvalidCastException
HResult=-2147467262
Message=La conversión de la cadena "" en el tipo 'Double' no es válida.
Source=Microsoft.VisualBasic
StackTrace:
en Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat)
en WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) en M:\Proyectos\Sueldos y descuentos\Sueldos y descuentos\Form1.vb:línea 6
en System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
en System.Windows.Forms.Control.WndProc(Message& m)
en System.Windows.Forms.ButtonBase.WndProc(Message& m)
en System.Windows.Forms.Button.WndProc(Message& m)
en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
en Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
en Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
en Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
en WindowsApplication1.My.MyApplication.Main(String[] Args) en 17d14f5c-a337-4978-8281-53493378c1071.vb:línea 81
en System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
en Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
en System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
en System.Threading.ThreadHelper.ThreadStart()
InnerException: System.FormatException
HResult=-2146233033
Message=La cadena de entrada no tiene el formato correcto.
Source=Microsoft.VisualBasic
StackTrace:
en Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
en Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat)
InnerException:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim VSB, VDES As Double VDES = 0 VSB = CDbl(TextBox4.Text) If CheckBox1.Checked Then VDES = VDES + VSB * 0.11 End If If CheckBox2.Checked Then VDES = VDES + 15 End If If CheckBox3.Checked Then VDES = VDES + CDbl(TextBox1.Text) End If TextBox2.Text = VDES TextBox3.Text = CStr(VSB - VDES) End Sub Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged TextBox1.Enabled = CheckBox3.Checked End Sub Private Sub Form1_Load(ByVal sender As System.Object, e As System.EventArgs) Handles MyBase.Load TextBox1.Enabled = False End Sub Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.EnabledChanged TextBox1.Clear() End Sub End Class
Respuestas
-
Hola:
El mensaje que te arroja es debido a que el control TextBox1.Text no contiene un valor numérico valido y es debido a que el valor "" no es convertible a ningún tipo de dato numerico.
Para solucionar esto cambia la manera en que realizas el CAST usando el Double.TryParse.
Revisa la documentación del link que te adjunto y analiza los ejemplos.
Saludos desde Monterrey, Nuevo León, México!!!
- Propuesto como respuesta Sergio Parra sábado, 4 de julio de 2015 10:53
- Marcado como respuesta Karen MalagónModerator lunes, 6 de julio de 2015 17:37
Todas las respuestas
-
-
Hola:
El mensaje que te arroja es debido a que el control TextBox1.Text no contiene un valor numérico valido y es debido a que el valor "" no es convertible a ningún tipo de dato numerico.
Para solucionar esto cambia la manera en que realizas el CAST usando el Double.TryParse.
Revisa la documentación del link que te adjunto y analiza los ejemplos.
Saludos desde Monterrey, Nuevo León, México!!!
- Propuesto como respuesta Sergio Parra sábado, 4 de julio de 2015 10:53
- Marcado como respuesta Karen MalagónModerator lunes, 6 de julio de 2015 17:37