c# - Convert textbox text to int - Error even after TryParse() -


what should (hopefully) simple problem...

i have function called updatechart(), program takes value input textbox (txtbp), , tries convert integer stored in local variable (latestreading) , used graph coordinate.

i tried this:

int latestreading = convert.toint32(txtbp.text); 

this caused run-time error informing me "input string not in correct format". after research have learned convert text textbox int, should use tryparse method. tried method out such:

int x = 0; int latestreading = 0;  if (int32.tryparse(txtbp.text, out x)) {     latestreading = convert.toint32(txtbp.text); } else {     messagebox.show("invalid reading!"); } 

i sure work, when came testing, entering the value 1 textbox myself caused jump 'else' part of statement. have read around on stack overflow can't find similar situation.

just let know, got thing working.

calling updatechart() function on button click seemed throwing off, calling inside function called on button click, seems able access data textbox. still not entirely sure how happens no complaining.

thank you help!

mark


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -