Validating empty textbox in VB.NET -


i´m beginner , trying build windows phone app vb.net. want validate empty textbox once start app, blocked , shows following exception error.this calculate fine if fields filled if field empty appears error.

el código de usuario no controló system.invalidcastexception   hresult=-2147467262   message=input string not in correct format.   source=conversionvbnet   stacktrace:        @ microsoft.visualbasic.compilerservices.conversions.tointeger(string value)        @ conversionvbnet.coursegswca.calculatebtn_click(object sender, routedeventargs e)        @ system.windows.controls.primitives.buttonbase.onclick()        @ system.windows.controls.button.onclick()        @ system.windows.controls.primitives.buttonbase.onmouseleftbuttonup(mousebuttoneventargs e)        @ system.windows.controls.control.onmouseleftbuttonup(control ctrl, eventargs e)        @ ms.internal.jolthelper.fireevent(intptr unmanagedobj, intptr unmanagedobjargs, int32 argstypeindex, int32 actualargstypeindex, string eventname)   innerexception: system.formatexception        hresult=-2146233033        message=input string not in correct format.        source=conversionvbnet        stacktrace:             @ microsoft.visualbasic.compilerservices.conversions.parsedouble(string value)             @ microsoft.visualbasic.compilerservices.conversions.tointeger(string value)        innerexception:  

and it´s code:

 private sub calculatebtn_click(sender object, e routedeventargs) handles calculatebtn.click     dim windspeed string = wsptxt.text     dim windirection string = wdtxt.text     dim heading string = headingtxt.text     dim speed string = tastxt.text     dim valor string = datosmsg.text       if string.isnullorempty(wsptxt.text.tostring())         messagebox.show("faltan datos")     elseif string.isnullorempty(wdtxt.text.tostring())         messagebox.show("faltan datos")     elseif string.isnullorempty(headingtxt.text.tostring())         messagebox.show("faltan datos")     elseif string.isnullorempty(tastxt.text.tostring())         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 happen this. tried many ways , appear same error.

thanks in advance

reg

there several ways convert strings int32. 1 implementing, cint, throws system.invalidcastexception invalid casting.


in code, testing string.isnullorempty allowing code continue running, , later fail cast after presented messagebox. 1 way handle might add exit sub after show message box, not handle possible errors.
put section of code in try block, , catch system.invalidcastexception handle error, or implement different conversion method. maybe like:

    dim windspeed int32     dim windirection int32     dim heading int32     dim speed int32      if int32.tryparse(wsptxt.text, windspeed) andalso         int32.tryparse(wdtxt.text, windirection) andalso         int32.tryparse(headingtxt.text, windirection) andalso         int32.tryparse(tastxt.text, windirection)         datosmsg.text = (windspeed + windirection + heading + speed).tostring     else         messagebox.show("faltan datos")     end if 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -