Compute Square Root using Math.Sqrt in VB.NET

Submitted by: 
Visitors have accessed this post 6382 times.

In this article, i will introduce another function in VB.NET regarding the Math Functions, the Math.Sqrt(). Math.Sqrt() function provides to compute the square root of a number. This will help the students to solve their quizzes and exams regarding how to get a square root of a number by only a manual solving. haha. LOL. :)

So, now let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add two TextBoxes named TextBox1 and TextBox2 then leave it as blank. TextBox1 will be your whole number as an input, and TextBox2 will be the result of the square root you've input. Now, add a Button named Button1 to see the result of the Square Root and displayed in TextBox2. You must design your layout like this:

square root design

3. Now, put this code in Button1_Click. This will display the result of the square root in TextBox2.

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim num1 As Integer
  3. num1 = Val(TextBox1.Text)
  4. TextBox2.Text = Math.Sqrt(num1)
  5. End Sub

We initialized num1 as Integer to hold the value inputted in TextBox1. Then in TextBox2, we compute the square root of a number inputted in num1 with the syntax Math.Sqrt(num1). Math.Sqrt() Function is only for calculating the square root of number.

Output:
output

Download the source code below and try it! :)

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
STI College - Surigao City
Mobile: 09488225971
E-mail:[email protected]

Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


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.