Dim Smallest As Integer
Dim SecondSmallest As Integer
Dim Counter As Integer
Option Explicit
Private Sub Form_Load()
DisplayButton.Enabled = False
End Sub
Private Sub DisplayButton_Click()
Picture1.Print SecondSmallest; "is the second smallest number"
End Sub
Private Sub EnterButton_Click()
Dim N As Integer
N = NumberBox.Text
If Counter < 2 Then
Counter = Counter + 1
SecondSmallest = N
Smallest = N
ElseIf Counter >= 2 Then
DisplayButton.Enabled = True
If N <= SecondSmallest Then
SecondSmallest = Smallest
Smallest = N
Else
Smallest = N
End If
ElseIf N > Smallest And N < SecondSmallest Then
SecondSmallest = N
End If
Counter = Counter + 1
Picture1.Cls
End Sub
Finding Second Smallest Number
Page 1 of 12 Replies - 530 Views - Last Post: 17 November 2012 - 09:18 AM
#1
Finding Second Smallest Number
Posted 13 November 2012 - 07:25 PM
What I am trying to do is find the second smallest number as inputted from the user. Also, the button used to display when I can display the second smallest number can only appear after two entries have been made. What i have so far is a weird code that works sometimes if I input numbers from Large to small but not small to large. I am rather stuck but this is what I have so far.
Replies To: Finding Second Smallest Number
#2
Re: Finding Second Smallest Number
Posted 14 November 2012 - 01:47 AM
Have a look at your main IF statement as a starting point.
The second ElseIf, looks as though it shouldn't be there, but should be inside the first Elseif, otherwise it's unlikely to get executed.
So something like:
The second ElseIf, looks as though it shouldn't be there, but should be inside the first Elseif, otherwise it's unlikely to get executed.
So something like:
If Counter < 2 then ' Do something Else ' Do Something else End if
#3
Re: Finding Second Smallest Number
Posted 17 November 2012 - 09:18 AM
A couple of simplifications: set your enabled property to false in design mode rather than in the load event. Use a label to display your value rather than the picture control.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|