# Finding Second Smallest Number

Page 1 of 1

## 2 Replies - 1452 Views - Last Post: 17 November 2012 - 09:18 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=300077&amp;s=cb5e089ac16c30aad15b427c6e6552b5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jlessard93

Reputation: 1
• Posts: 11
• Joined: 08-October 12

# 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.
```Dim Smallest As Integer
Dim SecondSmallest As Integer
Dim Counter As Integer
Option Explicit
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
```

Is This A Good Question/Topic? 0

## Replies To: Finding Second Smallest Number

### #2 maj3091

• D.I.C Lover

Reputation: 330
• Posts: 1,998
• Joined: 26-March 09

## 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:

```If Counter < 2 then
' Do something
Else
' Do Something else
End if
```

### #3 BobRodes

• Lovable Curmudgeon

Reputation: 600
• Posts: 3,071
• Joined: 19-May 09

## 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.