I need to write a Windows Form application in visual studio that contain a text box and it shows the prime number from 1 to 100 and those number are separated by "|"
For example it looks like this 1 | 2 | 3 | 5 ...
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
IsPrime()
End Sub
Private Sub IsPrime()
Dim checkPrime = 1, i, primeNumber As Integer
For primeNumber = 1 To 100
For i = 2 To primeNumber - 1
If primeNumber Mod i = 0 Then
checkPrime = 0 'Not prime number'
Exit For
Else
checkPrime = 1 'Is prime number
End If
Next
If checkPrime = 1 Then
Me.Txt_PrimeNumber.Text = primeNumber.ToString "| "
End If
Next
End Sub
But now when i run it, it only display
97|
CodePudding user response:
Fixed it, its a typo
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
IsPrime()
End Sub
Private Sub IsPrime()
Dim checkPrime = 1, i, primeNumber As Integer
For primeNumber = 1 To 100
For i = 2 To primeNumber - 1
If primeNumber Mod i = 0 Then
checkPrime = 0 'Not prime number'
Exit For
Else
checkPrime = 1 'Is prime number
End If
Next
If checkPrime = 1 Then
Me.Txt_PrimeNumber.Text = primeNumber.ToString " | "
End If
Next
End Sub