Type Complesso
Re As Double
Im As Double
Mo As Double
Ph As Double
End Type
Function LeggiCellaComplessa(cella As String) As Complesso
stringa = Range(cella).Value
S = Split(stringa, "exp(i") ' 2 exp( i3) --> S(0)=" 2 " , S(1)=" 3 )"
If S(0) <> stringa Then ' se nella stringa compare "exp(i"
S(0) = Trim(S(0)) ' S(0)="2"
S(1) = Trim(S(1)) ' S(1)="3)"
S(1) = Left(S(1), Len(S(1)) - 1) ' S(0)="3 ";
S(1) = Trim(S(1)) ' S(1)="3"
LeggiCellaComplessa.Mo = S(0)
LeggiCellaComplessa.Ph = S(1)
LeggiCellaComplessa.Re = S(0) * Cos(S(1))
LeggiCellaComplessa.Im = S(0) * Sin(S(1))
Else
S = Split(stringa, "i") ' 2 + i 3 --> S(0)=" 2 + " , S(1)=" 3 "
If S(0) <> stringa Then ' se nella stringa compare "i"
S(0) = Trim(S(0)) ' S(0)="2 +"
segno = Right(S(0), 1) ' segno="+";
S(0) = Left(S(0), Len(S(0)) - 1) ' S(0)="2 ";
S(0) = Trim(S(0)) ' S(0)="2";
S(1) = Trim(S(1)) ' S(1)="3"
If segno = "-" Then
S(1) = -1 * S(1)
End If
LeggiCellaComplessa.Re = S(0)
LeggiCellaComplessa.Im = S(1)
LeggiCellaComplessa.Mo = Sqr(S(0) ^ 2 + S(1) ^ 2)
If S(0) >= 0 Then
LeggiCellaComplessa.Ph = Atn(S(1) / S(0))
Else
LeggiCellaComplessa.Ph = Atn(S(1) / S(0)) + Pi
End If
Else
LeggiCellaComplessa.Re = 0
LeggiCellaComplessa.Im = 0
LeggiCellaComplessa.Mo = 0
LeggiCellaComplessa.Ph = 0
End If
End If
End Function
|