How to use Math.Max Function in VB.NET
Submitted by donbermoy on Monday, February 17, 2014 - 17:16.
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:
3. Now, put this code in Button1_Click. This will choose the larger number if you input in your Textbox1 and Textbox2.
We initialized
Next, Try to input TextBox1 a bigger number than Textbox2. It will have an output like this:
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,

- Public Class Form1
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim y As Integer, x As Integer
- Dim result As Integer
- y = TextBox1.Text
- x = TextBox2.Text
- result = Math.Max(y, x)
- If result = y Then
- Else
- End If
- End Sub
- End Class
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:


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
- 505 views