Private Sub Form_Load()
divisori.Visible = False
comdiv.Visible = False
fatt.Visible = False
End Sub
Private Sub ok_Click()
On Error Resume Next
Dim B As Boolean
Dim Y As Integer, Numero As Integer, I As Integer
If IsNumeric(num.Text) = False Then GoTo nonum
If num.Text > 1000000000 Then GoTo big
Numero = Val(Abs(num.Text))
num.Text = Numero
divisori.Clear
Label1.Caption = "Caricamento"
Label1.Visible = False
divisori.Clear
Y = Int(Numero / 2)
B = False
divisori.Visible = False
Label1.Caption = Numero & " è primo"
Label1.Visible = True
For I = 2 To Y
If Numero / I = Int(Numero / I) Then
If B = False Then
B = True
divisori.Visible = True
End If
Label1.Caption = "Divisori di " & Numero
divisori.AddItem I
End If
Next I
Exit Sub
nonum:
MsgBox "Inserisci un valore numerico", vbCritical, "Errore, tipo non numerico"
num.Text = ""
Exit Sub
big:
MsgBox "Inserisci un numero < di 1.000.000.000", vbExclamation, "Troppo grande"
num.Text = ""
End Sub
Private Sub ok1_click()
On Error Resume Next
Dim div(2, 50) As Integer, di(2)
Dim B As Boolean
Dim I As Integer, Y As Integer, Numero As Integer, J As Integer
B = True
comdiv.Clear
For I = 1 To 2
If IsNumeric(n(I).Text) = False Then GoTo nonum
Numero = Val(Abs(n(I).Text))
n(I).Text = Numero
If Numero > 10000000 Then GoTo big
Y = Int(Numero / 2)
di(I) = 0
For J = 2 To Y
If Numero / J = Int(Numero / J) Then
di(I) = di(I) + 1
div(I, di(I)) = J
End If
Next J
Next I
For I = 1 To di(1)
For J = 1 To di(2)
If div(1, I) = div(2, J) Then
B = False
comdiv.Visible = True
lbldiv.Visible = True
lbldiv.Caption = "Divisori comuni di " & n(1) & " e " & n(2)
comdiv.AddItem div(1, I)
End If
Next J
Next I
If B = True Then
comdiv.Visible = False
lbldiv.Visible = True
lbldiv.Caption = n(1) & " e " & n(2) & " sono primi tra loro"
End If
Exit Sub
nonum:
MsgBox "Inserisci un valore numerico", vbCritical, "Errore, tipo non corrispondente"
n(I).Text = ""
Exit Sub
big:
MsgBox "Inserisci un numero < 10.000.000", vbExclamation, "Reinserisci numero"
n(I).Text = ""
End Sub
Private Sub ok2_Click()
On Error Resume Next
Dim I As Integer, y1 As Integer, y2 As Integer, Meno As Integer, Piu As Integer, MM As Integer
For I = 0 To 1
If IsNumeric(x(I).Text) = False Then GoTo nonum
If x(I).Text > 1000000000 Then GoTo big
If x(I).TabIndex = 0 Then GoTo zero
Next I
y1 = CLng(Abs(Val(x(0))))
y2 = CLng(Abs(Val(x(1))))
minimo = "L' m.c.m. di " & y1 & " e " & y2 & " è "
If y1 > y2 Then
Piu = y1
Meno = y2
End If
If y1 <= y2 Then
Piu = y2
Meno = y1
End If
MM = Meno
'MCD
Do Until y1 / Meno = Int(y1 / Meno) And y2 / Meno = Int(y2 / Meno)
Meno = Meno - 1
Loop
If Meno = 1 Then mcd.Caption = y1 & " e " & y2 & " sono primi tra loro"
If Meno <> 1 Then mcd.Caption = "L' M.C.D. di " & y1 & " e " & y2 & " è " & Meno
'mcm
Exit Sub
zero:
MsgBox "Errore, impossibile eseguire l' operazione", vbCritical, "Divisione per zero"
x(I).Text = ""
Exit Sub
nonum:
MsgBox "Inserisci un valore numerico", vbCritical, "Errore, tipo non corrispondente"
x(I).Text = ""
Exit Sub
big:
MsgBox "Inserisci un numero < 1.000.000.000", vbExclamation, "Reinserisci numero"
x(I).Text = ""
End Sub
Private Sub ok3_Click()
On Error Resume Next
Dim B As Boolean
B = True
If IsNumeric(primo.Text) = False Then GoTo nonum
If primo.Text > 1000000000 Then GoTo big
Numero = Val(Abs(primo.Text))
primo.Text = Numero
fatt.Clear
Y = Int(Numero / 2)
fatt.Visible = False
For I = 2 To Y
If Numero / I = Int(Numero / I) Then B = False
Next I
If B = True Then MsgBox Numero & " è un numero primo", vbInformation, "Impossibile eseguire la scomposizione in fattori"
If B = False Then
fatt.Visible = True
numerodiviso = Numero
Do Until numerodiviso = 1
divx = 2
Do Until numerodiviso / divx = Int(numerodiviso / divx)
divx = divx + 1
Loop
numerodiviso = numerodiviso / divx
fatt.AddItem divx
Loop
End If
Exit Sub
nonum:
MsgBox "Inserisci un valore numerico", vbCritical, "Errore, tipo non numerico"
primo.Text = ""
Exit Sub
big:
MsgBox "Inserisci un numero < di 1.000.000.000", vbExclamation, "Troppo grande"
primo.Text = ""
End Sub