procedure TForm1.btnCalcClick(Sender: TObject);

var

fVolt, fAmp, fResist, fWatt, fBattLife, fBattMah: Single;

begin

// ============ Set all variables to 0 =====================

fVolt := 0;

fAmp := 0;

fResist := 0;

fWatt := 0;

fBattLife := 0;

fBattMah := 0;

// ========= Input initial variables =======================

if lblVolts.Text <> '' then

fVolt := StrToFloat(lblVolts.Text);

if lblAmps.Text <> '' then

fAmp := StrToFloat(lblAmps.Text);

if lblResistance.Text <> '' then

fResist := StrToFloat(lblResistance.Text);

if lblWatts.Text <> '' then

fWatt := StrToFloat(lblWatts.Text);

if lblBattMah.Text <> '' then

fBattMah := StrToFloat(lblBattMah.Text);

// ================== Ohms Law =============================

if ((fVolt > 0) and (fResist > 0)) then

begin

fAmp := fVolt / fResist;

fWatt := fVolt * fAmp;

end;

if ((fVolt > 0) and (fWatt > 0)) then

begin

fAmp := fWatt / fVolt;

fResist := fVolt / fAmp;

end;

if ((fVolt > 0) and (fAmp > 0)) then

begin

fWatt := fVolt * fAmp;

fResist := fVolt / fAmp;

end;

if ((fAmp > 0) and (fResist > 0)) then

begin

fVolt := fResist * fAmp;

fWatt := fVolt * fAmp;

end;

if ((fAmp > 0) and (fWatt > 0)) then

begin

fVolt := fWatt / fAmp;

fResist := fVolt / fAmp;

end;

if ((fResist > 0) and (fWatt > 0)) then

begin

fVolt := Sqrt(fWatt * fResist);

fAmp := fWatt / fVolt;

end;

// ================= Calculat Battery Life ===================

if ((fBattMah > 0) and (fAmp > 0)) then

begin

fBattLife := ((fBattMah / 1000) / Power(fAmp, 1.25));

lblBattLife.Text := FormatFloat('0.00 Hrs', fBattLife);

end;

// ================ Display Results ==========================

if ((fVolt > 0) and (fAmp > 0) and (fResist > 0) and (fWatt > 0)) then

begin

lblVolts.Text := FormatFloat('0.0', fVolt);

lblAmps.Text := FormatFloat('0.00', fAmp);

lblResistance.Text := FormatFloat('0.0', fResist);

lblWatts.Text := FormatFloat('0.00', fWatt);

end;

end;