Prime Numbers in Visual Basic 6
Monday, November 22, 2010 by: Andy Kurnia Prayoga Madedescription: This program made with Visual Basic 6 programming language. The objective of this program is to find a series of prime numbers. We enter the lower limit at the upper limit in text1 and text2. Then the results of these series of prime numbers we show in text3. For more details, follows the source code of this program. Good luck!
Private Sub Command1_Click() Dim i As Integer Dim a As Integer Dim prima As Boolean Dim hasil As String If (Text1.Text = "" Or Text2.Text = "") Then MsgBox "Isi dulu batas bawah dan atas.", vbExclamation, "Error" ElseIf (Text1.Text < 2) Then MsgBox "Batas bawah harus diatas 1", vbExclamation, "Error" ElseIf (CInt(Text1.Text) > CInt(Text2.Text)) Then MsgBox "Batas Atas harus lebih besar atau sama dengan Batas Bawah", vbExclamation, "Error" Else For i = Text1.Text To Text2.Text prima = True For a = 2 To (i - 1) If (i Mod a = 0) Then prima = False Exit For End If Next a If prima Then If (hasil = "") Then hasil = i Else hasil = hasil & ", " & i End If End If Next i Text3.Text = hasil End If End Sub