How to use Math.Min Function in VB.NET
Submitted by donbermoy on Wednesday, February 19, 2014 - 16:04.
Last day, I introduced the Math.Max Function in VB.Net. Now I will introduce the opposite of it, the Math.Min Function.
Math.Min is a function in vb.net that has its class in Math. Math.Min() Mathematical Function in Visual Basic.Net is used to return the smallest of two decimal or integer 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 which is a smaller number between the two. You must design your layout like this:
3. Now, put this code in Button1_Click. This will choose the smaller number if you input in your Textbox1 and Textbox2.
We initialized
- 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.Min(y, x)
- If result = y Then
- Else
- End If
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 smaller number between the two inputs of x and y as we used Math.Min. If the smaller number is on num1 it will display "Smaller integer value is: " & result & " on num1" as the result (our variable for smaller number) is equal to the value of y. Otherwise, it will display "Smaller integer value is: " & result & " on num2" in which the num2 or the TextBox2 holds a smaller number than TextBox1.
Testing:Try to input TextBox1 a smaller number than Textbox2. It will have an output like this:
Next, Try to input TextBox1 a smaller 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,
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
- 642 views