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 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 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 = 0) 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 Sub CalcolaRadici(E As Integer, P As Double, Grado As Double)
Dim A As Double
Dim B As Double
Dim X2 As Double
Dim Y2 As Double
Dim X1 As Double
Dim Y1 As Double
Y1 = Round(P * Sin(((Grado + 360 * W) / E) * Pi / 180), 3)
X1 = Round(P * Cos(((Grado + 360 * W) / E) * Pi / 180), 3)
lsRisultati.AddItem "W(" & W & ")=" & vbTab & P & " * cos " & GPS((Grado + 360 * W) / E) & " + " & P & " * sin " & GPS((Grado + 360 * W) / E) & vbTab & "=" & X1 & " + " & Y1 & "i"
picGrafico.DrawWidth = 4
picGrafico.PSet (X1, Y1), vbBlue
If W = 0 Then
A = X1
B = Y1
End If
picGrafico.DrawWidth = 1
If W <> 0 Then picGrafico.Line (X1, Y1)-(X2, Y2), vbRed
If W = E - 1 Then picGrafico.Line (X1, Y1)-(A, B), vbRed
X2 = X1
Y2 = Y1
End Sub
Private Sub cmdRisultato_Click()
On Error GoTo Errore
Dim E As Integer
Dim P As Double
Dim W As Integer
Dim Grado As Double
lsRisultati.Clear
picGrafico.Refresh
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
E = txtEsponente
P = Round(Sqr((txtReale) ^ 2 + (txtImmaginario) ^ 2), 3)
If P <> 0 Then
picGrafico.Scale (-P * 1.1, P * 1.1)-(P * 1.1, -P * 1.1)
picGrafico.Line (-P * 1.1, 0)-(P * 1.1, 0), vbBlack
picGrafico.Line (0, P * 1.1)-(0, -P * 1.1), vbBlack
picGrafico.DrawWidth = 4
picGrafico.PSet (XS * txtReale, YS * txtImmaginario), vbMagenta
End If
For W = 0 To E - 1
CalcolaRadici E, P, Grado
Next W
Exit Sub
Errore:
MsgBox "Errore n. " & Err.Number & vbCrLf & Err.Description, vbCritical
End Sub
Private Sub Form_Load()
RipristinoEsponente = txtEsponente
RipristinoReale = txtReale
RipristinoImmaginario = txtImmaginario
XS = 1
YS = 1
End Sub
Private Sub lsRisultati_Click()
For W = 0 To E
CalcolaRadici E, P, Grado
Next W
CalcolaRadici(
End Sub
Private Sub lsRisultati_DblClick()
txtRisultato.Text = lsRisultati.List(lsRisultati.ListIndex)
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 picGrafico_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblCoordinate.Caption = "X " & X & " - Y " & Y
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_Click()
Clipboard.Clear
Clipboard.SetText txtRisultato
End Sub