Dim x As Integer Dim i As Integer Dim Flag As Boolean = False x = TextBox1.Text For i = 2 To x / 2 If (i = x) Then i = i + 1 If (x Mod i = 0) Then Flag = True Exit For End If Next If (Flag = False) Then ' this num is prime number MsgBox("PRIME") Else ' this num is not prime number MsgBox("NOT PRIME") End If