Sunday, 15 March 2015

vb.net - Is possible to ignore the TextBox? -



vb.net - Is possible to ignore the TextBox? -

i'm creating programme calculate average. there 12 textbox , want create possibility leave fields blank. there errors , crash of program. possible create that?

this part of code:

italianoscritto = (textbox1.text) matematicascritto = (textbox2.text) inglesescritto = (textbox3.text) informaticascritto = (textbox4.text) scienzescritto = (textbox5.text) fisicascritto = (textbox6.text) mediascritto = (italianoscritto + matematicascritto + inglesescritto + informaticascritto + scienzescritto + fisicascritto) / 6 label10.text = str(mediascritto)

if leave blank textbox1 when click on button calculate average vb says cast not valid string "" type 'single' , bar of te textbox1 become yellow

i following: iterate on textboxes , check if can parse value iteger. if yes, add together value list. add together values list , split number of cases. faster big if-statements , resilient against error

dim tblist new list(of textbox) 'add textboxes list here tblist.add(textbox1) ... dim vallist new list(of integer) each elem in tblist dim value integer if integer.tryparse(elem.text,value)=true vallist.add(value) else 'report error or nil end if next dim result integer dim maxval integer =0 each elem in vallist maxval +=elem next result = maxval / vallist.count

if need back upwards point values, take double or single instead of integer. also: regardless -check if values in textboxes numbers or not. if omit tryparse, come in "a" , app crash , burn

also: alternative strict on!

vb.net textbox

No comments:

Post a Comment