|
-
May 14th, 2013, 08:28 PM
#1
Thread Starter
Lively Member
Need help trying to figure out how to write the code
I hope I'm explaining this correctly. Is there a way to immediately update a user form as the user answer's the form. i.e. Lets say the user form has two text boxes, four radio buttons (marked with labels + - * /) and a label used for the answer. After the user enters a number in textbox1 as soon as they start to type a number in textbox2, depending on which mathematical operation they chose, the label(answer) would change as soon as they type a digit. Hope that makes sense. Thanks for your help.
-
May 14th, 2013, 08:54 PM
#2
Re: Need help trying to figure out how to write the code
Handle the TextChanged event of TextBox2. You can perform the entire calculation and display the result in the Label each time.
-
May 14th, 2013, 09:37 PM
#3
Thread Starter
Lively Member
Re: Need help trying to figure out how to write the code
First let me say thank you for your help. Second let me also say I'm knew to Visual Basic. I hate to ask this but would you mind explaining how I would go about doing this? thank you again.
-
May 14th, 2013, 10:15 PM
#4
Re: Need help trying to figure out how to write the code
You should work your way through a good beginners tutorial, e.g.
http://www.homeandlearn.co.uk/net/vbnet.html
Once you've been through that, you should know how to do everything you need to for this problem and more besides.
-
May 14th, 2013, 10:17 PM
#5
Thread Starter
Lively Member
Re: Need help trying to figure out how to write the code
Thank you again for your help. I'll try it out.
-
May 14th, 2013, 11:58 PM
#6
Re: Need help trying to figure out how to write the code
Just a word of warning, if the user selects "/" and enters a zero as the first character in TextBox2 you're going to have to ignore it otherwise you'll get a 'Division by Zero' error when you attempt the calculation. It may be better to ignore the first character if it's a zero whatever operator the user has chosen.
Also, if you're going to handle Real Numbers (as opposed to just Integers) you'll have to cater for the decimal point. You'll also have to cater for a sign (e.g. "+" or "-") being entered as the first character.
-
May 15th, 2013, 12:03 AM
#7
Thread Starter
Lively Member
Re: Need help trying to figure out how to write the code
just curious, but which handle for textbox two would I use to achieve this? Could come in handy for other things. Also, are there any drawbacks to doing this?
-
May 15th, 2013, 12:28 AM
#8
Re: Need help trying to figure out how to write the code
 Originally Posted by pooky
just curious, but which handle for textbox two would I use to achieve this? Could come in handy for other things.
I assume you mean to ask which event you should handle and, if so, I answered that question in post #2.
 Originally Posted by pooky
Also, are there any drawbacks to doing this?
The good thing about doing it that way is that the result is there for the user as soon as they finish typing the value. The bad thing is that you're wasting your time performing the calculation as the user is typing because they aren't interested in those results. There's no way to know for sure that the user has finished entering data unless you make them initiate the calculation, which you'd normally do by using a Button. The calculation and subsequent display is going to be very quick in your case, so it's no big deal. If what you had to do was a bit time-consuming then it would be a bad idea to do it on every change of the Text. In that case what you can do is start/restart a Timer with a fairly small Interval on each TextChanged event and only do whatever it is that you have to do when it Ticks. That means that there's no wasted effort as the user types as long as they don't pause along the way. When they stop typing, their data will be used after a small delay.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|