Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Visual Basic .application values will not update

Status
Not open for further replies.

trchambe

Electrical
Oct 8, 2009
46
0
0
US
Hello all,

I am a novice programmer, and have recently began creating simple calculator applications using Visual Basic (I am a power engineer... these are small applications for basic but tedious calculations).

I have often found that after I enter all my data and return a result, if I change a few input values and recalculate, the results will not update.

I am only using text boxes and radio buttons to input information, and a single button to calculate the results.

I have noticed that if I change a radiobutton to a selection that I do not want, hit my calculate button, then return my radio button to my desired selection and hit calculate once more, it will work. Even this does not always work, however. It seems I must change the radiobutton setting several times.

Finally, this situation has occurred on all of my created applications that do implement a radio button.

Is there something that I am missing, or has anyone run into this before?
 
Replies continue below

Recommended for you

Do you want it to automatically recalculate when you choose a different radio button, or do you mean that when you change the input and hit recalculate you do not get the action you were expecting?
 
I will choose a different radio button, hit recalculate, and the result does not change. I put in a textbox with the radio button variable linked to it, and it does not change. If I recycle, however, (select the desired button, another button, and the desired button), it often works.
 
Can you post some relevant code, or if you don't want to post it to the internet, maybe some example code that demonstrates your problem?

Offhand, I would say it sounds like the recalculate routine is not updating values for some radio buttons before it runs. Perhaps add some code to the 'on change' event for the radio buttons to update values?

Which version of Visual Basic are you using?
 
You have to read all the textbox and options, all input values, each time you recalculate. Your calculation subroutine needs to look like these,

sub calculate()
a = value(txtBoxA.text)
b= value(txtBoxB.text)
c = value(txtBoxC.text)
d = a * b * c 'or whatever
txtBoxD.text = format(d,"###.##")
end sub

**********************
"The problem isn't finding the solution, its trying to get to the real question." BigInch
 
If I remember a similar situation - you need a "CALC" button that actaully re-reads all your input and redoes the calculation. OR

When you exit a text box - I think you can see that event and go to your calc sub-routines each time.
 
Ya you could recalculate on each keypress event too, but that could get pretty messy. A direct to a sub on a control's "lose focus" event would work, but as I recall, that event doesn't actually fire until you click on another control, which is why I probably settled on the re-read input method inside the calc button for a more uniform "feel". That method doesn't require any additional lines of code either, which you'd get a lot of if you had many inputs and had to put a sub's name under the lostfocus event of each one of them.

**********************
"The problem isn't finding the solution, its trying to get to the real question." BigInch
 
Status
Not open for further replies.
Back
Top