Option Explicit
Dim m, a, i, say, sure As Single
Dim s, s2 As Single
Dim asal(1000000) As Single
Dim at, met As String
Dim dur As Boolean
Dim eng As Boolean
Dim gen, yuk As Single
Private Sub cmd_dil_Click()
eng = Not eng
If eng = True Then
Caption = "Prime Number Searcher - www.alieskici.com"
Label1.Caption = "Number"
o(1).Caption = "Is that a prime number?"
o(0).Caption = "Find prime numbers"
Label2.Caption = "First"
Label3.Caption = "Last"
o(2).Caption = "Prime factors"
o(3).Caption = "Twin primes"
Frame1.Caption = "Interval of indice"
cmd_hesapla.Caption = "Calculate"
cmd_dur.Caption = "Stop"
cmd_yeni.Caption = "New"
cmd_dil.Caption = "Turkce"
cmd_hak.Caption = "About"
cmd_kap.Caption = "Exit"
Else
Caption = "ASAL ARASTIRICI - www.alieskici.com"
Label1.Caption = "Sayi"
o(1).Caption = "Sayi asal mi?"
o(0).Caption = "Asallari bul"
Label2.Caption = "Ilk"
Label3.Caption = "Son"
o(2).Caption = "Asal carpanlar"
o(3).Caption = "Ikiz asallar"
Frame1.Caption = "Indis araligi"
cmd_hesapla.Caption = "Hesapla"
cmd_dur.Caption = "dur"
cmd_yeni.Caption = "Yeni"
cmd_dil.Caption = "English"
cmd_hak.Caption = "Hakkinda"
cmd_kap.Caption = "Kapat"
End If
End Sub
Private Sub cmd_dur_Click()
dur = True
dugmeler
End Sub
Private Sub cmd_hesapla_Click()
On Error GoTo hata
cmd_hesapla.Visible = False
cmd_dur.Visible = True
ts.Text = ""
ti.Text = ""
met = ""
dur = False
DoEvents
sure = Timer
t.Text = Trim(Str(Int(Val(t.Text))))
If Val(t.Text) - s < 0 And o(2).Value = False Then
For i = Val(tind1.Text) To Val(tind2.Text)
If asal(i) < Val(t.Text) Then met = met & asal(i) & " " Else Exit For
Next
ts.Text = met
sure = Abs(Timer - sure) * 1000
If eng = True Then
ti.Text = "Total prime number: " & i
ti.Text = ti.Text & at & "Rate of prime number: % " & Int(i / Val(t.Text) * 1000) / 10
ti.Text = ti.Text & at & "Calculating time: " & Format(sure, "###,###") & " miliseconds"
Else
ti.Text = "Toplam asal sayi: " & i
ti.Text = ti.Text & at & "Asal sayi orani: % " & Int(i / Val(t.Text) * 1000) / 10
ti.Text = ti.Text & at & "Hesaplama suresi: " & Format(sure, "###,###") & " milisaniye"
End If
dugmeler
Exit Sub
End If
s = Val(t.Text)
If s < 2 Then
t.Text = ""
t.SetFocus
dugmeler
Exit Sub
End If
If eng = True Then
ti.Text = "Processing. Please wait ...."
Else
ti.Text = "Islem yapiliyor. Lutfen bekleyin ...."
End If
say = 1
asal(1) = 2
If o(0).Value = True Then
If asal(2) <> 0 Then GoTo s3
asalbul
ElseIf o(1).Value = True Then
a = Fix(Val(t.Text) / 2)
If (Val(t.Text) - a * 2) = 0 Then
ti.Text = ""
If eng = True Then
ts.Text = "Not a prime number"
Else
ts.Text = "Asal degil"
End If
dugmeler
Exit Sub
End If
For m = 3 To Sqr(s) Step 2
a = Fix(Val(t.Text) / m)
' a l i es ki ci .c om
If (Val(t.Text) - a * m) = 0 Then
ti.Text = ""
If eng = True Then
ts.Text = "Not a prime number"
Else
ts.Text = "Asal degil"
End If
Exit Sub
End If
Next
If eng = True Then
ts.Text = "A prime number"
Else
ts.Text = "Asal"
End If
ti.Text = ""
dugmeler
Exit Sub
ElseIf o(2).Value = True Then
asalbul
s2 = s
Dim ussay As Single
For i = 1 To say
ussay = 0
bol1:
a = Int(s2 / asal(i))
If s2 - a * asal(i) = 0 Then
s2 = a
ussay = ussay + 1
If ussay = 1 Then ts.Text = ts.Text & asal(i)
GoTo bol1
Else
GoTo bol2
End If
bol2:
If ussay > 1 Then ts.Text = ts.Text & " ^ " & Trim(Str(ussay)) & ", "
If ussay = 1 Then ts.Text = ts.Text & ", " ' a l i es ki c i .c o m
Next
ts.Text = Left(ts.Text, Len(ts.Text) - 2)
sure = Abs(Timer - sure) * 1000
dugmeler
If eng = True Then
ti.Text = "Number factored to its prime numbers"
ti.Text = ti.Text & at & "Calculating time: " & Format(sure, "###,###") & " miliseconds"
Else
ti.Text = "Sayi asal carpanlarina ayrildi."
ti.Text = ti.Text & at & "Hesaplama suresi: " & Format(sure, "###,###") & " milisaniye"
End If
Exit Sub
ElseIf o(3).Value = True Then
asalbul
End If
s2:
tind2.Text = Trim(Str(say))
If Abs(Val(tind1.Text) - Val(tind2.Text)) > 3999 Or Abs(Val(tind1.Text) - Val(tind2.Text)) > say - 1 Then
If eng = True Then
ti.Text = "Indice interval can't be more than 3999. Automatic appointment will do. (This process for no being of errors and to fast operation.)"
Else
ti.Text = "Indis araligi farki 3999'dan buyuk olmamali. Otomatik atama yapilacak. (Bu islem hata olusmamasi ve hizli islem yapilmasi icindir.)"
End If
tind2.Text = Trim(Str(say))
tind1.Text = Trim(Str(say - 3999))
' al i e s ki c i .c om
If say - 3999 < 1 Then
tind1.Text = "1"
Else
End If
End If
s3:
If o(3).Value = False Then
For i = Val(tind1.Text) To Val(tind2.Text)
If asal(i) <> 0 Then met = met & asal(i) & " "
Next
Else
If Val(tind1.Text) = 1 Then tind1.Text = "2"
For i = Val(tind1.Text) To Val(tind2.Text)
If Abs(asal(i) - asal(i - 1)) = 2 Then met = met & asal(i - 1) & " " & asal(i) & " "
Next
End If
ts.Text = met
sure = Abs(Timer - sure) * 1000
If eng = True Then
ti.Text = "Total prime number: " & i
ti.Text = ti.Text & at & "Rate of prime number: % " & Int(i / Val(t.Text) * 1000) / 10
ti.Text = ti.Text & at & "Calculating time: " & Format(sure, "###,###") & " miliseconds"
Else
ti.Text = "Toplam asal sayi: " & say 'a l i es ki ci .c om
ti.Text = ti.Text & at & "Asal sayi orani: % " & Int(say / Val(t.Text) * 1000) / 10
ti.Text = ti.Text & at & "Hesaplama suresi: " & Format(sure, "###,###") & " milisaniye"
End If
dugmeler
Exit Sub
hata:
If eng = True Then
MsgBox ("Entered number is too big."), vbExclamation, ("Prime Number Searcher")
Else
MsgBox ("Girilen sayi cok buyuk."), vbExclamation, ("Asal Arastirici")
End If
dugmeler
End Sub
Function asalbul()
For m = 3 To s Step 2
For i = 1 To Int(Sqr(m))
a = Int(m / asal(i))
If (m - a * asal(i)) = 0 Then GoTo s1
Next
say = say + 1
asal(say) = m
s1:
If dur = True Then
If eng = True Then
ti.Text = "Process stopped !"
Else
ti.Text = "Islem durduruldu !"
End If
Exit Function
End If
DoEvents
Next
End Function
Sub dugmeler()
cmd_hesapla.Visible = True
cmd_dur.Visible = False
End Sub
Private Sub cmd_kap_Click()
End ' al i es ki ci .c om
End Sub
Private Sub cmd_web_Click()
On Error GoTo webhata
Dim X As Variant
X = Shell("start http://www.alieskici.com")
Exit Sub
webhata:
If eng = True Then
MsgBox ("Error !"), vbCritical, ("Prime Number Searcher")
Else
MsgBox ("Hata !"), vbCritical, ("Asal Arastirici")
End If
End Sub
Private Sub cmd_yeni_Click()
t.Text = ""
ts.Text = ""
ti.Text = ""
met = ""
tind1 = ""
tind2 = ""
dur = False
t.SetFocus
For i = 1 To 1000000
asal(i) = 0
Next
End Sub
Private Sub Form_Load()
at = Chr(13) & Chr(10)
gen = Width
yuk = Height
End Sub
Private Sub Form_Resize()
If WindowState = 1 Then Exit Sub
Width = gen
Height = yuk
End Sub
Private Sub lad_Click()
cmd_web_Click
End Sub