Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Terne Pitagoriche - frmMain.frm

frmMain.frm

Caricato da: Alceus
Scarica il programma completo

  1. Option Explicit
  2. Dim i As Long, j As Long, Primo As Integer, Secondo As Integer, terzo As Integer, Mcm As Integer, Messaggio As String
  3. Sub MCD(A As Integer, B As Integer)
  4. While A <> B
  5. If A > B Then
  6. A = A - B
  7. Else
  8. B = B - A
  9. End If
  10. Wend
  11. If A = 1 Then MsgBox "La terna pitagorica è primitiva!", vbInformation
  12. If A <> 1 Then
  13. MsgBox "La terna pitagorica è derivata!", vbInformation
  14. Messaggio = MsgBox("Vuoi renderla primitiva?", vbExclamation + vbYesNo)
  15. Select Case Messaggio
  16. Case vbYes
  17. Text1.Text = Val(Text1.Text) / A
  18. Text2.Text = Val(Text2.Text) / A
  19. Text3.Text = Val(Text3.Text) / A
  20. End Select
  21. End If
  22. End Sub
  23. Private Sub Command1_Click()
  24. On Error Resume Next
  25. If Val(Text3.Text) = Sqr(Val((Text1.Text) ^ 2) + Val((Text2.Text) ^ 2)) Then
  26. MsgBox "La terna formata dai numeri " + Str(Text1.Text) + "," + Str(Text2.Text) + " e" + Str(Text3.Text) + " è pitagorica", vbInformation
  27. Command3.Enabled = True
  28. Else
  29. MsgBox "La terna formata dai numeri " + Str(Text1.Text) + "," + Str(Text2.Text) + " e" + Str(Text3.Text) + " non è pitagorica", vbInformation
  30. Correggi.Enabled = True
  31. End If
  32. End Sub
  33. Private Sub Command2_Click()
  34. Text1.Text = "Primo numero"
  35. Text2.Text = "Secondo numero"
  36. Text3.Text = "Terzo numero"
  37. If Correggi.Enabled = True Then Correggi.Enabled = False
  38. If Command1.Enabled = True Then Command1.Enabled = False
  39. End Sub
  40. Private Sub Command3_Click()
  41. Call MCD(Text1.Text, Text2.Text)
  42. Command3.Enabled = False
  43. End Sub
  44. Private Sub Correggi_Click()
  45. Text3.Text = Sqr(Val((Text1.Text) ^ 2) + Val((Text2.Text) ^ 2))
  46. Correggi.Enabled = False
  47. End Sub
  48. Private Sub Form_Load()
  49. Command1.Enabled = False
  50. Correggi.Enabled = False
  51. Command3.Enabled = False
  52. End Sub
  53. Private Sub Form_Unload(Cancel As Integer)
  54. MsgBox "Il programma 'Terne pitagoriche' è stato creato da Alceus, membro della Community di PieroTofy.It", vbInformation
  55. End Sub
  56.  
  57. Private Sub Text1_Change()
  58. If Text2.Text <> "" And Text2.Text <> "Secondo numero" And Text3.Text <> "" And Text3.Text <> "Terzo numero" Then Command1.Enabled = True
  59. End Sub
  60. Private Sub Text2_Change()
  61. If Text1.Text <> "" And Text1.Text <> "Primo numero" And Text3.Text <> "" And Text3.Text <> "Terzo numero" Then Command1.Enabled = True
  62. End Sub
  63. Private Sub Text3_Change()
  64. If Text1.Text <> "" And Text1.Text <> "Primo numero" And Text2.Text <> "" And Text2.Text <> "Secondo numero" Then Command1.Enabled = True
  65. End Sub
  66. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
  67. If KeyCode = vbKeyBack And Text1.SelStart Then
  68. Text1.Text = Left$(Text1.Text, Text1.SelStart - 1) & Right(Text1.Text, Len(Text1.Text) - Text1.SelStart)
  69. End If
  70. End Sub
  71. Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
  72. If KeyCode = vbKeyBack And Text2.SelStart Then
  73. Text2.Text = Left$(Text2.Text, Text2.SelStart - 1) & Right(Text2.Text, Len(Text2.Text) - Text2.SelStart)
  74. End If
  75. End Sub
  76. Private Sub Text3_KeyDown(KeyCode As Integer, Shift As Integer)
  77. If KeyCode = vbKeyBack And Text3.SelStart Then
  78. Text3.Text = Left$(Text3.Text, Text3.SelStart - 1) & Right(Text3.Text, Len(Text3.Text) - Text3.SelStart)
  79. End If
  80. End Sub
  81. Private Sub Text1_KeyPress(KeyAscii As Integer)
  82. If InStr("0123456789.", Chr$(KeyAscii)) = 0 Then KeyAscii = 0
  83. End Sub
  84. Private Sub Text2_KeyPress(KeyAscii As Integer)
  85. If InStr("0123456789.", Chr$(KeyAscii)) = 0 Then KeyAscii = 0
  86. End Sub
  87. Private Sub Text3_KeyPress(KeyAscii As Integer)
  88. If InStr("0123456789.", Chr$(KeyAscii)) = 0 Then KeyAscii = 0
  89. End Sub
  90. Private Sub Text1_Click()
  91. If Text1.Text = "Primo numero" Then Text1.Text = ""
  92. End Sub
  93. Private Sub Text1_LostFocus()
  94. If Text1.Text = "" Then Text1.Text = "Primo numero"
  95. End Sub
  96. Private Sub Text2_Click()
  97. If Text2.Text = "Secondo numero" Then Text2.Text = ""
  98. End Sub
  99. Private Sub Text2_LostFocus()
  100. If Text2.Text = "" Then Text2.Text = "Secondo numero"
  101. End Sub
  102. Private Sub Text3_Click()
  103. If Text3.Text = "Terzo numero" Then Text3.Text = ""
  104. End Sub
  105. Private Sub Text3_LostFocus()
  106. If Text3.Text = "" Then Text3.Text = "Terzo numero"
  107. End Sub