|
-
Jul 31st, 2010, 07:14 AM
#6
Thread Starter
Lively Member
Re: Find Closest Match
This works perfectly! Thank you!!!
 Originally Posted by .paul.
try this:
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim numbers() As Integer = {100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 600, 700, 800, 900, 1000}
Dim closest As Integer
Dim closestDifference As Integer = Integer.MaxValue
Dim inputNumber As Integer
If Integer.TryParse(TextBox1.Text, inputNumber) Then
For x As Integer = 0 To numbers.GetUpperBound(0)
If Math.Abs(inputNumber - numbers(x)) < closestDifference Then
closestDifference = Math.Abs(inputNumber - numbers(x))
closest = numbers(x)
End If
Next
MsgBox(closest)
End If
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|