Math Functions in VB.NET

Today, I will teach you how to create a program that has math functions in Visual Basic.NET. Here you will learn about Abs, Log, Round, Sin, Cos, and Tan Function. 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 txtNum for your inputted number and txtOut for the output. Insert 6 Buttons named btnAbs for Absolute Value, btnLog for Logarithm, btnRound for Rounding off, btnSin for finding the sine of an angle, btnCos for the Cosine of an angle, and btnTan for the Tangent of the angle. You must design your interface like this: design 3. In your btnAbs for Absolute Value, copy this code below. This Abs function will return absolute value of our inputted number, means even if we input negative number, the output will be positive.
  1.     Private Sub btnAbs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbs.Click
  2.         txtOut.Text = Math.Abs(Val(txtNum.Text))
  3.     End Sub
Output: output 4. In your btnLog for finding the Logarithm of a number, copy this code below. This Log function will return the logarithmic value of our inputted number.
  1.     Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click
  2.         txtOut.Text = Math.Log(Val(txtNum.Text))
  3.     End Sub
Output: output 5. In your btnRound for rounding off a number, copy this code below. This Round function will return the inputted number to nearest the specified value. It means that if the nearest value after the decimal point is 5, then it will increase by 1 the whole number. Otherwise, the whole number will be the same.
  1.     Private Sub btnRound_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRound.Click
  2.         txtOut.Text = Math.Round(Val(txtNum.Text))
  3.     End Sub
Output: output 6. In your btnSin for finding the sine value of the inputted number (angle), copy this code below. This Sin function will return the specifying the sine of an angle as our inputted number.
  1.     Private Sub btnSin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSin.Click
  2.         txtOut.Text = Math.Sin(Val(txtNum.Text))
  3.     End Sub
Output: output 7. In your btnCos for finding the cosine value of the inputted number (angle), copy this code below. This Cosine function will return the specifying the cosine of an angle as our inputted number.
  1.     Private Sub btnCos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCos.Click
  2.         txtOut.Text = Math.Cos(Val(txtNum.Text))
  3.     End Sub
Output: output 7. In your btnTan for finding the tangent value of the inputted number (angle), copy this code below. This Tan function will return the specifying the tangent of an angle as our inputted number.
  1.     Private Sub btnTan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTan.Click
  2.         txtOut.Text = Math.Tan(Val(txtNum.Text))
  3.     End Sub
Output: output Hope this helps! :) Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment