How to use Math.Min Function in VB.NET

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: design 3. Now, put this code in Button1_Click. This will choose the smaller number if you input in your Textbox1 and Textbox2.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim y As Integer, x As Integer
  3.         Dim result As Integer
  4.         y = TextBox1.Text
  5.         x = TextBox2.Text
  6.         result = Math.Min(y, x)
  7.         If result = y Then
  8.             MsgBox("Smaller integer value is: " & result & " on num1")
  9.         Else
  10.             MsgBox("Smaller integer value is: " & result & " on num2")
  11.         End If
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 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: output Next, Try to input TextBox1 a smaller number than Textbox2. It will have an output like this: 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