Code Wont Work

M

Minitman

Greetings,

I am trying to get a figure in a UserForm using a CommandButton
called "Calculate". I have 7 TextBoxes. Data is entered
automatically into TB7 and TB11. TB16 is the total that I enter to
try and (break-up). TB9 and TB13 may or may not have data.
TB15 is a fudge factor to make the result come out to within a 1/4
hour. That leaves TB8 for the total time figure to be calculated.

This is what I came up with so far:

Private Sub CalculateButton_Click()

If Not TB8.Text = "" Then
TB8.Text = CStr((CDbl(TB16.Text) - CDbl(TB15.Text)) / _
(CDbl(1 + TB11)) - CDbl(TB9.Text) + _
CDbl(TB13.Text) - CDbl(TB15.Text))
End If

End Sub

Does anyone see anything even a little "hinkey"? I have gone over
this formula countless times, but I can't get it to work - HELP!!!!!!

Any help would be most appreciated
 
S

Sharad

Change your code as below and try:


If Not TB8.Text = "" Then
TB8.Text = (Val(TB16.Text) - Val(TB15.Text)) / _
(1 + Val(TB11.Text)) - Val(TB9.Text) + _
Val(TB13.Text) - Val(TB15.Text))
End If

If any textbox from 9 to 15 is empty, CDbl(thattextbox.text) will give
error - Type mismatch.
Val will convert it to 0.
If you are sure that one of these will be empty then CDbl should work
BUT:
CDbl(1 + TB11) is worng. First of all it should TB11.Text and secodly
it should be (1 + CDBl(TB11.Text))

Sharad

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
M

Minitman

Hey Sharad,

Thanks. I am indeed having type mismatch errors. :^(

This looks like just what I am looking for. :^)

And many thanks for the pointers - I need them! <G>

I will have to test out the code modifications later, when I am more
awake.

-Minitman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top