Option Explicit
Public RipristinoEsponente As String
Public RipristinoReale As String
Public RipristinoImmaginario As String
Public XS As Integer
Public YS As Integer
Const Pi As Double = 3.141592653589
Private Sub Seleziona(Oggetto As TextBox)
Oggetto.SelStart = 0
Oggetto.SelLength = Len(Oggetto)
Oggetto.SetFocus
End Sub
Private Sub Controllo(Oggetto As TextBox, Ripristino As String)
Dim I As Integer
Oggetto = Val(Oggetto)
If Oggetto = 0 Then Seleziona Oggetto
For I = 1 To Len(Oggetto)
If (Asc(Mid(Oggetto, I, 1)) < 48 Or Asc(Mid(Oggetto, I, 1)) > 59) Or (Oggetto = 0 And Oggetto.TabIndex = 2) Then Oggetto.Text = Ripristino
Ripristino = Abs(Oggetto.Text)
Next I
End Sub
Private Function Segno(Index As Integer) As Integer
If Index = 0 Then Segno = -1
If Index = 1 Then Segno = 1
End Function
Private Function GPS(ByVal Gradi As Double) As String
Dim G As Double
Dim P As Double
Dim S As Double
Do Until Gradi < 360
Gradi = Gradi - 360
Loop
G = Int(Gradi)
Gradi = (Gradi - G) * 100
Gradi = Gradi * 3 / 5
P = Int(Gradi)
Gradi = (Gradi - P) * 100
Gradi = Gradi * 3 / 5
S = Int(Gradi)
GPS = G & "° " & P & "' " & S & """"
End Function
Private Sub cmdRisultati_Click()
Dim Grado As Integer
Dim P As Integer
If txtReale = 0 Or txtImmaginario = 0 Then
If txtReale = 0 And optSImmaginario(0).Value = True Then Grado = 270
If txtReale = 0 And optSImmaginario(1).Value = True Then Grado = 90
If txtImmaginario = 0 And optSReale(0).Value = True Then Grado = 180
If txtImmaginario = 0 And optSReale(1).Value = True Then Grado = 0
Else
Grado = Atn(YS * txtImmaginario / XS * txtReale) * 180 / Pi
If YS = -1 Then Grado = Grado + 180
End If
P = Sqr(txtReale ^ 2 + txtImmaginario ^ 2)
txtRisultato.Text = "(Z)^" & txtEsponente & "=" & String(5, " ") & P & "*(cos " & GPS(Grado * txtEsponente) & " + i*sin " & GPS(Grado * txtEsponente) & ")=" & String(5, " ") & P * Round(Cos(Grado * txtEsponente * Pi / 180), 4) & " + " & Round(Sin(Grado * txtEsponente * Pi / 180), 4) & "i"
End Sub
Private Sub Form_Load()
XS = 1
YS = 1
RipristinoReale = txtReale
RipristinoImmaginario = txtImmaginario
RipristinoEsponente = txtEsponente
End Sub
Private Sub optSImmaginario_Click(Index As Integer)
YS = Segno(Index)
End Sub
Private Sub optSReale_Click(Index As Integer)
XS = Segno(Index)
End Sub
Private Sub txtEsponente_Change()
Controllo txtEsponente, RipristinoEsponente
End Sub
Private Sub txtEsponente_GotFocus()
Seleziona txtEsponente
End Sub
Private Sub txtImmaginario_Change()
Controllo txtImmaginario, RipristinoImmaginario
End Sub
Private Sub txtImmaginario_GotFocus()
Seleziona txtImmaginario
End Sub
Private Sub txtReale_Change()
Controllo txtReale, RipristinoReale
End Sub
Private Sub txtReale_GotFocus()
Seleziona txtReale
End Sub
Private Sub txtRisultato_DblClick()
Clipboard.Clear
Clipboard.SetText txtRisultato
End Sub