20 Program to check entered number on textbox in prime or not using button in VB.NET

Code:

Public Class Form1

    Dim num, temp, i As Integer
    Dim b As Boolean

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        num = TextBox1.Text
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        temp = num
        i = 2
        b = False
        While i < num

            If temp Mod i = 0 Then
                b = True
                GoTo b
            End If

            i += 1

        End While

b:
        If b Then
            MsgBox("Number is Not  Prime ")
        Else
            MsgBox("Number is  Prime ")
        End If
    End Sub
End Class


Output:  


Previous
Next Post »