Android Question Sqrt Problem

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.
 

James Chamblin

Active Member
Licensed User
Longtime User
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.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top