Help

  • Thread starter Thread starter saziz
  • Start date Start date
S

saziz

I am trying to write a code to calculate efficiency of a process. Th
following code gives me "Object Required' Error Please educate me.

Private Sub CommandButton1_Click()
Dim NetLoad As Variant
Dim AveCoatWt As Variant
Dim WtGain As Variant
Dim solutionapplied As Variant

NetLoad.Value = TextBox1.Text

AveCoatWt.Value = TextBox2.Text
WtGain.Value = TextBox3.Text
solutiionapplied.Value = TextBox4.Text
TextBox5.Value = (TextBox4 / ((TextBox1 * TextBox2 * 1000000)
TextBox3))


End Sub

Thank you for your help.
Sye
 
Thank you Bruce for correction of typo. That did not helped.
How should I define solutionapplied?
Thanks
Syed
 
You declared these things:

Dim NetLoad As Variant
Dim AveCoatWt As Variant
Dim WtGain As Variant
Dim solutionapplied As Variant

But you never set them to anything.

What are they?
 
Then those things are just holders for the values from the textboxes?

If yes, then each of those things will hold a string -- until/unless you convert
it to something else. And since you're doing arithmetic with them, maybe...

Private Sub CommandButton1_Click()
Dim NetLoad As double
Dim AveCoatWt As double
Dim WtGain As double
Dim solutionapplied As double

NetLoad = cdbl(TextBox1.Text)
AveCoatWt = cdbl(TextBox2.Text)
WtGain = cdbl(TextBox3.Text)
solutionapplied = cdbl(TextBox4.Text)

TextBox5.Value = (TextBox4 / ((TextBox1 * TextBox2 * 1000000) * TextBox3))

End Sub

These are simple variables--not objects (like ranges, which have a .value
property).
 
Dave,
Thank you for the help.
What could be the format for % for textbox5 value?
I am trying this:
textbox5.text=format( formula, "%")
It gives me error.
Thnaks once again for your help.
Syed
 
Dave,
Thank you for the help.
What could be the format for % for textbox5 value?
I am trying this:
textbox5.text=format( formula, "%")
It gives me error.
Thnaks once again for your help.
Sye
 
Maybe...

textbox5.text=format( formula, "0.00%")

And you may not need those intermediate variables, too:

Option Explicit

Private Sub CommandButton1_Click()

TextBox5.Value _
= Format((Me.TextBox4.Value _
/ ((Me.TextBox1.Value * Me.TextBox2.Value * 1000000) _
* Me.TextBox3.Value)), "0.0%")

End Sub

But I would add some checks for numbers for each of those textboxes.
 
Back
Top