Visual Basic - Need Some Help

Pyroflea

Distinguished
Mar 18, 2007
341
0
18,930
Just started doing some VB again after about a year and a half. I'm making a calculator with a pretty specific purpose. I know how to make the program with buttons, but I can't seem to remember how you go about having things automatically calculate as you enter values, or if that's even possible in VB. Any info? Thanks.
 

Zenthar

Distinguished
Dec 31, 2007
250
0
18,960
Haven't programmed VB in a while, but exactly what would you want to automatically calculate? What you are looking might be some kind of "onKeyPress" or "onValueChange" events, but unless you give me an example there isn't more I can tell.
 

Pyroflea

Distinguished
Mar 18, 2007
341
0
18,930


It's used for calculating the needed port length in subwoofer boxes.

Program.png


I'm not 100% sure about how to go about doing this, to be quite honest. The first part is easy;
(Length - (2* Wood Thickness)) * (Width - (2* Wood Thickness)) * (Height - (2* Wood Thickness)) / 1728
But after that I want it to display the value given from that in the Gross Volume text box. After that there has to be some crazy math done, but I have all the equations typed out already.
 

blackhawk1928

Distinguished
Jul 15, 2008
236
2
18,860
I have and own a license of Microsoft Visual Studio 2008 Professional Edition, it has all the different microsoft developer programs like VB, web developer, c#,C++...etc all in one package and i could do a little bit of everything so cant really help you in specifics, however what I do know is that microsoft has an excellent massive forum called MSDN specifically for microsoft products like visual studio and all those developer programs and stuff and you can get much more help there, replies, and better assistance. Any question you have, that forum can help.
 

Pyroflea

Distinguished
Mar 18, 2007
341
0
18,930


Yeah, I got a license for VS2008 Pro from my tech teacher :D I'll go check out that forum. Thank you very much!
 

Pyroflea

Distinguished
Mar 18, 2007
341
0
18,930
Alright, well I decided to just go with a button for now just so that I could get it working and go from there. I got all my code written (took long enough...), and it compiles fine. But when I go to calculate, I get one error, and I have no clue what it means.

ERRORZ.png


Not quite sure what that means. Can supply code if needed.
 

Zenthar

Distinguished
Dec 31, 2007
250
0
18,960
This error seems to be caused by VB trying to convert an empty textbox value ("") to a double value. You might have to explicitly detect empty textbox and replace their value with some default one (ex: 0).

As for calculating "on the fly", the event you are looking for is either KeyPress to really calculate as the user type or FocusLost if you want the calculation to occur when the user leaves the field.
 

Pyroflea

Distinguished
Mar 18, 2007
341
0
18,930


Thank you for your reply. As for the error, I have resolved that issue.

For the calculating on the fly, I'll look into using one of those methods on the next version I make. Thank you very much!