TextBox to TextBox Calculations

Viewed 38

Maybe a simple question but I still need some help with a formula clarification:

Could somebody help me with this:

TempCalc = CInt(TextBox3.Value) * (16*POWER(SQRT(CInt(TextBox1.Value)*(1-CInt(Textbox1.Value)))/(CInt(TextBox1.Value)*CInt(TextBox2.Value);2))

what is wrong, is the syntax totally off?

Thanks in advance

1 Answers

The function POWER and SQRT do not exist in VBA.

  • Power(x, y) can be replaced with x ^ y
  • sqrt is sqr in VBA

So the following should work:

TempCalc = CLng(TextBox3.Value) * (16 * ((Sqr(CLng(TextBox1.Value) * 1 - CLng(TextBox1.Value))) / (CLng(TextBox1.Value) * CLng(TextBox2.Value))) ^ 2)

And I recommend to convert the integers to Long using CLng as there is no benefit in using Integer.

So to make it easier to debug I recommend to split the calculation:

Dim SqrtVal As Double
SqrtVal = Sqr(CLng(TextBox1.Value) * 1 - CLng(TextBox1.Value))

Dim DivVal As Double
DivVal = (CLng(TextBox1.Value) * CLng(TextBox2.Value))

Dim PowerVal As Double
PowerVal = (SqrtVal / DivVal) ^ 2

Dim TempCalc As Double
TempCalc = CLng(TextBox3.Value) * 16 * PowerVal
Related