Finding the Larger of 2 Numbers-VISUAL BASIC

November 15, 2010 at 07:47:38
Specs: Windows XP
Hello, I'm trying to write a code which would allow me to write 2 random numbers and then show the larger number when clicked on a button called "Display Largest", below you can see my code which I have written. If anyone is able to fix it for me - please do, thank you:


Public Class Form1
Dim First As Integer
Dim Second As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLargest.Click
First = Val(txtFirst.Text)
Second = Val(txtSecond.Text)
If First > Second Then
btnLargest = First 'Confused as to what write in here :/
MessageBox.Show("txtFirst.text")
Else
txtLargest = txtSecond 'Please help me with this part as well
MessageBox.Show("txtSecond")
'Basically I want to see the larger number when clicked on "btnLargest" (Button1_Click)
'I'm clearly having some problems with "IF" and "ELSE" functions.

End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
txtFirst.Clear()
txtSecond.Clear()
txtLargest.Clear()

End Sub

Private Sub txtbox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFirst.TextChanged

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub

Private Sub txtLargest_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLargest.TextChanged

End Sub
End Class



See More: Finding the Larger of 2 Numbers-VISUAL BASIC

Report •


#1
November 15, 2010 at 07:52:11
Here is a screenshot of the form:

http://www.ipix.lt/images/92841323.png


Report •

#2
November 15, 2010 at 08:01:47
If First > Second Then
Read this back to me, in plain English (no symbols).

How To Ask Questions The Smart Way


Report •

#3
November 16, 2010 at 01:55:32
If first number is larger than second, then it should appear in the third (last) textbox. Else, second number should appear if it is larger than the first one. I hope that it's plain enough for you.

Report •

Related Solutions

#4
November 16, 2010 at 02:06:21
Never mind, figured it out myself, it was supposed to be:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLargest.Click
First = Val(txtFirst.Text)
Second = Val(txtSecond.Text)
If First > Second Then
txtLargest.Text = First
Else
txtLargest.Text = Second
End If
End Sub


Report •


Ask Question