I had used the code for Sqrt in previous calculations but for some reason it does not work this time.
What did I do wrong?
B4X:
Sub btnCalc_Click
Dim Res As Float = edtResist.Text
Dim Watt As Float = edtWatt.Text
Dim Amp As Float = Watt / Res
Dim Volt As Float = (Volt * Volt) / Watt
Dim Ans1 As Float = Sqrt (Amp As Double) As Double
Dim Ans2 As Float = Sqrt (Volt As Double) As Double
lblAmps.Text = NumberFormat(Ans1, 1,2)
lblVolts.Text = NumberFormat( Ans2, 1,2)
End Sub
I get a red line under Dim Ans1 As Float. Descript Says: ')' expected.
Thanks in advance.
Should be Sqrt(Amp), not Sqrt(Amp As Double) As Double. The As Double is only used in Sub declaration, not when calling the sub. Amp will automatically be cast to Double when it is passed to the Sqrt Sub.