How to use Math.Max Function in VB.NET

In this article, i will introduce some function in VB.NET regarding the Math Functions. Math.Max is a function in vb.net that has its class in Math. Math.Max() Mathematical Function in Visual Basic.Net is used to return the largest of two decimal numbers. Note: This function is only applied in two integer or decimal numbers. 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. Now, add a Button named Button1 to compare who is a larger number between2. You must design your layout like this: math design 3. Now, put this code in Button1_Click. This will choose the larger number if you input in your Textbox1 and Textbox2.
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim y As Integer, x As Integer
  5.         Dim result As Integer
  6.         y = TextBox1.Text
  7.         x = TextBox2.Text
  8.         result = Math.Max(y, x)
  9.         If result = y Then
  10.             MsgBox("Largest integer value is: " & result & " on num1")
  11.         Else
  12.             MsgBox("Largest integer value is: " & result & " on num2")
  13.         End If
  14.     End Sub
  15. End Class
We initialized Dim y As Integer, x As Integer that y will be equal to the value of textbox1 as our num1 and x will be equal to the value of textbox2 as our num2. Next, we initialized Dim result As Integer as this chooses the larger number between the two inputs of x and y as we used Math.Max. It the larger number is on num1 it will display "Largest integer value is: " & result & " on num1" as the result (our variable for larger number) is equal to the value of y. Otherwise, it will display "Largest integer value is: " & result & " on num2" in which the num2 or the TextBox2 holds a greater number than TextBox1. Testing: Try to input TextBox1 a bigger number than Textbox2. It will have an output like this: math output1 Next, Try to input TextBox1 a bigger number than Textbox2. It will have an output like this: math output 2 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
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment