Option Explicit
Dim i As Long, j As Long, Primo As Integer, Secondo As Integer, terzo As Integer, Mcm As Integer, Messaggio As String
Sub MCD(A As Integer, B As Integer)
While A <> B
If A > B Then
A = A - B
Else
B = B - A
End If
Wend
If A = 1 Then MsgBox "La terna pitagorica è primitiva!", vbInformation
If A <> 1 Then
MsgBox "La terna pitagorica è derivata!", vbInformation
Messaggio = MsgBox("Vuoi renderla primitiva?", vbExclamation + vbYesNo)
Select Case Messaggio
Case vbYes
Text1.Text = Val(Text1.Text) / A
Text2.Text = Val(Text2.Text) / A
Text3.Text = Val(Text3.Text) / A
End Select
End If
End Sub
Private Sub Command1_Click()
On Error Resume Next
If Val(Text3.Text) = Sqr(Val((Text1.Text) ^ 2) + Val((Text2.Text) ^ 2)) Then
MsgBox "La terna formata dai numeri " + Str(Text1.Text) + "," + Str(Text2.Text) + " e" + Str(Text3.Text) + " è pitagorica", vbInformation
Command3.Enabled = True
Else
MsgBox "La terna formata dai numeri " + Str(Text1.Text) + "," + Str(Text2.Text) + " e" + Str(Text3.Text) + " non è pitagorica", vbInformation
Correggi.Enabled = True
End If
End Sub
Private Sub Command2_Click()
Text1.Text = "Primo numero"
Text2.Text = "Secondo numero"
Text3.Text = "Terzo numero"
If Correggi.Enabled = True Then Correggi.Enabled = False
If Command1.Enabled = True Then Command1.Enabled = False
End Sub
Private Sub Command3_Click()
Call MCD(Text1.Text, Text2.Text)
Command3.Enabled = False
End Sub
Private Sub Correggi_Click()
Text3.Text = Sqr(Val((Text1.Text) ^ 2) + Val((Text2.Text) ^ 2))
Correggi.Enabled = False
End Sub
Private Sub Form_Load()
Command1.Enabled = False
Correggi.Enabled = False
Command3.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBox "Il programma 'Terne pitagoriche' è stato creato da Alceus, membro della Community di PieroTofy.It", vbInformation
End Sub
Private Sub Text1_Change()
If Text2.Text <> "" And Text2.Text <> "Secondo numero" And Text3.Text <> "" And Text3.Text <> "Terzo numero" Then Command1.Enabled = True
End Sub
Private Sub Text2_Change()
If Text1.Text <> "" And Text1.Text <> "Primo numero" And Text3.Text <> "" And Text3.Text <> "Terzo numero" Then Command1.Enabled = True
End Sub
Private Sub Text3_Change()
If Text1.Text <> "" And Text1.Text <> "Primo numero" And Text2.Text <> "" And Text2.Text <> "Secondo numero" Then Command1.Enabled = True
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyBack And Text1.SelStart Then
Text1.Text = Left$(Text1.Text, Text1.SelStart - 1) & Right(Text1.Text, Len(Text1.Text) - Text1.SelStart)
End If
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyBack And Text2.SelStart Then
Text2.Text = Left$(Text2.Text, Text2.SelStart - 1) & Right(Text2.Text, Len(Text2.Text) - Text2.SelStart)
End If
End Sub
Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyBack And Text3.SelStart Then
Text3.Text = Left$(Text3.Text, Text3.SelStart - 1) & Right(Text3.Text, Len(Text3.Text) - Text3.SelStart)
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr("0123456789.", Chr$(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If InStr("0123456789.", Chr$(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If InStr("0123456789.", Chr$(KeyAscii)) = 0 Then KeyAscii = 0
End Sub
Private Sub Text1_Click()
If Text1.Text = "Primo numero" Then Text1.Text = ""
End Sub
Private Sub Text1_LostFocus()
If Text1.Text = "" Then Text1.Text = "Primo numero"
End Sub
Private Sub Text2_Click()
If Text2.Text = "Secondo numero" Then Text2.Text = ""
End Sub
Private Sub Text2_LostFocus()
If Text2.Text = "" Then Text2.Text = "Secondo numero"
End Sub
Private Sub Text3_Click()
If Text3.Text = "Terzo numero" Then Text3.Text = ""
End Sub
Private Sub Text3_LostFocus()
If Text3.Text = "" Then Text3.Text = "Terzo numero"
End Sub