Option Explicit
Const Pi As Double = 3.14159
Const MinX As Integer = -1000
Const MaxX As Integer = 5000
Const MaxY As Integer = 1000
Const MinY As Integer = -1000
Const Unit As Integer = 1000
Dim Col(4) As ColorConstants
Dim Spe(4) As Integer
Private Sub Controllo(Oggetto As TextBox)
If Oggetto <> "" Then
If IsNumeric(Oggetto) = False Then GoTo NoNum
If Oggetto < 0 Or Oggetto > 10000000 Then GoTo NnAccettabile
Oggetto.SelStart = Len(Oggetto)
End If
Exit Sub
NoNum:
MsgBox "Errore, tipo non corrispondente", vbCritical
Oggetto.Text = ""
Oggetto.SetFocus
Exit Sub
NnAccettabile:
MsgBox "Errore,inserisci un numero maggiore o uguale a 0 e minore o ugale a 10000000", vbExclamation
Oggetto.SelStart = 0
Oggetto.SelLength = Len(Oggetto)
Oggetto.SetFocus
End Sub
Private Sub DisegnaOnde()
On Error Resume Next
Dim i, j As Integer
Pic.Refresh
For i = MinX To MaxX
Pic.DrawWidth = Spe(1)
If chkSCTA(1).Value = 1 Then Pic.PSet (i, txtAlt(1) / 1000 * Cos(i * Pi / 180 * 1 / txtPeriodo(1)) * Unit), Col(1)
Pic.DrawWidth = Spe(2)
If chkSCTA(2).Value = 1 Then Pic.PSet (i, txtAlt(2) / 1000 * Sin(i * Pi / 180 * 1 / txtPeriodo(2)) * Unit), Col(2)
Pic.DrawWidth = Spe(3)
If chkSCTA(3).Value = 1 Then Pic.PSet (i, txtAlt(3) / 1000 * Tan(i * Pi / 180 * 1 / txtPeriodo(3)) * Unit), Col(3)
Pic.DrawWidth = Spe(4)
If chkSCTA(4).Value = 1 Then Pic.PSet (i, txtAlt(4) / 1000 / Tan(i * Pi / 180 * 1 / txtPeriodo(4)) * Unit), Col(4)
Next i
End Sub
Private Sub chkAssi_Click()
DisegnaAssi
End Sub
Private Sub DisegnaAssi()
If chkSCTA(0).Value = 1 Then
Pic.DrawWidth = Spe(0)
Pic.Line (0, MaxY)-(0, MinY), Col(0)
Pic.Line (MinX, 0)-(MaxX, 0), Col(0)
End If
End Sub
Private Sub chkSCTA_Click(Index As Integer)
DisegnaOnde
DisegnaAssi
End Sub
Private Sub ColSCTA_Click(Index As Integer)
CDialog.ShowColor
Col(Index) = CDialog.Color
chkSCTA_Click (Index)
End Sub
Private Sub ColSfondo_Click()
CDialog.ShowColor
Pic.BackColor = CDialog.Color
End Sub
Private Sub Form_Load()
Pic.Scale (MinX, MaxY)-(MaxX, MinY)
Col(0) = vbWhite
Col(1) = vbGreen
Col(2) = vbBlue
Col(3) = vbRed
Col(4) = vbYellow
Spe(0) = 1
Spe(1) = 1
Spe(2) = 1
Spe(3) = 1
Spe(4) = 1
End Sub
Private Sub SpeSCTA_Click(Index As Integer)
Spe(Index) = InputBox("Inserisci lo sessore del trato della funzione " & SpeSCTA(Index).Caption & vbCrLf & "Inserisci un numero intero compreso tra 1 e 20", "Trigonometria", Pic.DrawWidth)
If IsNumeric(Spe(Index)) = False Then GoTo NoNum
If Spe(Index) < 1 Or Spe(Index) > 20 Then GoTo Fuori
chkSCTA_Click (Index)
Exit Sub
NoNum:
MsgBox "Errore, inserisci valore numerico", vbCritical, "Tipo non corrispondente"
Exit Sub
Fuori:
MsgBox "Errore, insrisci un numero intero compreso tra 1 e 20", vbExclamation, "Trigonometria"
End Sub
Private Sub txtAlt_Change(Index As Integer)
Controllo txtAlt(Index)
chkSCTA_Click (Index)
End Sub
Private Sub txtPeriodo_Change(Index As Integer)
Controllo txtPeriodo(Index)
chkSCTA_Click (Index)
End Sub