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
Che numeri - Che numeri... 0123456789....frm

Che numeri... 0123456789....frm

Caricato da: Antometal
Scarica il programma completo

  1. Private Sub Form_Load()
  2. divisori.Visible = False
  3. comdiv.Visible = False
  4. fatt.Visible = False
  5. End Sub
  6.  
  7. Private Sub ok_Click()
  8. On Error Resume Next
  9. Dim B As Boolean
  10. Dim Y As Integer, Numero As Integer, I As Integer
  11.     If IsNumeric(num.Text) = False Then GoTo nonum
  12.     If num.Text > 1000000000 Then GoTo big
  13. Numero = Val(Abs(num.Text))
  14. num.Text = Numero
  15. divisori.Clear
  16. Label1.Caption = "Caricamento"
  17. Label1.Visible = False
  18. divisori.Clear
  19. Y = Int(Numero / 2)
  20. B = False
  21. divisori.Visible = False
  22. Label1.Caption = Numero & " è primo"
  23. Label1.Visible = True
  24.     For I = 2 To Y
  25.             If Numero / I = Int(Numero / I) Then
  26.                     If B = False Then
  27.                         B = True
  28.                         divisori.Visible = True
  29.                     End If
  30.                 Label1.Caption = "Divisori di " & Numero
  31.                 divisori.AddItem I
  32.             End If
  33.     Next I
  34.    
  35. Exit Sub
  36. nonum:
  37. MsgBox "Inserisci un valore numerico", vbCritical, "Errore, tipo non numerico"
  38. num.Text = ""
  39. Exit Sub
  40. big:
  41. MsgBox "Inserisci un numero < di 1.000.000.000", vbExclamation, "Troppo grande"
  42. num.Text = ""
  43. End Sub
  44.  
  45. Private Sub ok1_click()
  46. On Error Resume Next
  47. Dim div(2, 50) As Integer, di(2)
  48. Dim B As Boolean
  49. Dim I As Integer, Y As Integer, Numero As Integer, J As Integer
  50. B = True
  51. comdiv.Clear
  52.     For I = 1 To 2
  53.             If IsNumeric(n(I).Text) = False Then GoTo nonum
  54.         Numero = Val(Abs(n(I).Text))
  55.         n(I).Text = Numero
  56.             If Numero > 10000000 Then GoTo big
  57.         Y = Int(Numero / 2)
  58.         di(I) = 0
  59.             For J = 2 To Y
  60.                     If Numero / J = Int(Numero / J) Then
  61.                         di(I) = di(I) + 1
  62.                         div(I, di(I)) = J
  63.                     End If
  64.             Next J
  65.     Next I
  66.    
  67.     For I = 1 To di(1)
  68.         For J = 1 To di(2)
  69.                 If div(1, I) = div(2, J) Then
  70.                     B = False
  71.                     comdiv.Visible = True
  72.                     lbldiv.Visible = True
  73.                     lbldiv.Caption = "Divisori comuni di " & n(1) & " e " & n(2)
  74.                     comdiv.AddItem div(1, I)
  75.                 End If
  76.         Next J
  77.     Next I
  78.     If B = True Then
  79.         comdiv.Visible = False
  80.         lbldiv.Visible = True
  81.         lbldiv.Caption = n(1) & " e " & n(2) & " sono primi tra loro"
  82.     End If
  83.    
  84. Exit Sub
  85. nonum:
  86. MsgBox "Inserisci un valore numerico", vbCritical, "Errore, tipo non corrispondente"
  87. n(I).Text = ""
  88. Exit Sub
  89. big:
  90. MsgBox "Inserisci un numero < 10.000.000", vbExclamation, "Reinserisci numero"
  91. n(I).Text = ""
  92. End Sub
  93.  
  94. Private Sub ok2_Click()
  95. On Error Resume Next
  96. Dim I As Integer, y1 As Integer, y2 As Integer, Meno As Integer, Piu As Integer, MM As Integer
  97.     For I = 0 To 1
  98.             If IsNumeric(x(I).Text) = False Then GoTo nonum
  99.             If x(I).Text > 1000000000 Then GoTo big
  100.             If x(I).TabIndex = 0 Then GoTo zero
  101.     Next I
  102.    
  103. y1 = CLng(Abs(Val(x(0))))
  104. y2 = CLng(Abs(Val(x(1))))
  105. minimo = "L' m.c.m. di " & y1 & " e " & y2 & " è "
  106.     If y1 > y2 Then
  107.         Piu = y1
  108.         Meno = y2
  109.     End If
  110.     If y1 <= y2 Then
  111.         Piu = y2
  112.         Meno = y1
  113.     End If
  114.     MM = Meno
  115.     'MCD
  116.     Do Until y1 / Meno = Int(y1 / Meno) And y2 / Meno = Int(y2 / Meno)
  117.         Meno = Meno - 1
  118.     Loop
  119.     If Meno = 1 Then mcd.Caption = y1 & " e " & y2 & " sono primi tra loro"
  120.     If Meno <> 1 Then mcd.Caption = "L' M.C.D. di " & y1 & " e " & y2 & " è " & Meno
  121.    
  122.     'mcm
  123.    
  124. Exit Sub
  125. zero:
  126. MsgBox "Errore, impossibile eseguire l' operazione", vbCritical, "Divisione per zero"
  127. x(I).Text = ""
  128. Exit Sub
  129. nonum:
  130. MsgBox "Inserisci un valore numerico", vbCritical, "Errore, tipo non corrispondente"
  131. x(I).Text = ""
  132. Exit Sub
  133. big:
  134. MsgBox "Inserisci un numero < 1.000.000.000", vbExclamation, "Reinserisci numero"
  135. x(I).Text = ""
  136. End Sub
  137.  
  138. Private Sub ok3_Click()
  139. On Error Resume Next
  140. Dim B As Boolean
  141. B = True
  142.     If IsNumeric(primo.Text) = False Then GoTo nonum
  143.     If primo.Text > 1000000000 Then GoTo big
  144. Numero = Val(Abs(primo.Text))
  145. primo.Text = Numero
  146. fatt.Clear
  147. Y = Int(Numero / 2)
  148. fatt.Visible = False
  149.     For I = 2 To Y
  150.             If Numero / I = Int(Numero / I) Then B = False
  151.     Next I
  152.     If B = True Then MsgBox Numero & " è un numero primo", vbInformation, "Impossibile eseguire la scomposizione in fattori"
  153.     If B = False Then
  154.         fatt.Visible = True
  155.         numerodiviso = Numero
  156.             Do Until numerodiviso = 1
  157.                 divx = 2
  158.                     Do Until numerodiviso / divx = Int(numerodiviso / divx)
  159.                         divx = divx + 1
  160.                     Loop
  161.                 numerodiviso = numerodiviso / divx
  162.                 fatt.AddItem divx
  163.             Loop
  164.     End If
  165.    
  166. Exit Sub
  167. nonum:
  168. MsgBox "Inserisci un valore numerico", vbCritical, "Errore, tipo non numerico"
  169. primo.Text = ""
  170. Exit Sub
  171. big:
  172. MsgBox "Inserisci un numero < di 1.000.000.000", vbExclamation, "Troppo grande"
  173. primo.Text = ""
  174. End Sub