How to Get Prime Numbers in VB.Net

Submitted by: 
Visitors have accessed this post 170 times.

Now, let’s create a simple program which is how to get prime numbers in VB.Net. You will learn here how to easily determine the prime numbers between 1 to 100. This simple program is also powerful that you can use to test large numbers to see if they are “prime”. Just follow the steps below.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application. Then, add a Button and a Label in the Form just like shown below.
prime21

Step 2

Double click the Button to fire the click event handler of it and do the following codes for getting the prime numbers from 1 to 100.

  1. Dim prime, numbers, i As Integer
  2. prime = 1
  3. MsgBox(“The prime Numbers are : ”)
  4. For numbers = 1 To 100
  5. For i = 2 To numbers - 1
  6. If numbers Mod i = 0 Then
  7. prime = 0
  8. Exit For
  9. Else
  10. prime = 1
  11. End If
  12.  
  13. Next
  14. If prime = 1 Then
  15. MsgBox(numbers)
  16. End If
  17. Next

For any questions about this article. You can contact me @

Email – [email protected]
Mobile No. – 09305235027 – TNT
FB Account – https://www.facebook.com/onnaj.soicalap


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.