'Question : find the closest number from a random series of number
Dim arr
arr = array(1,43,76,89,100,122,1876)
IntVal=cint(inputbox("Enter The number"))
arrSize=ubound(arr)
For i=0 to 6
If cint(arr(i))<IntVal and IntVal<cint(arr(i+1)) Then
diffback=IntVal-arr(i)
msgbox diffback
difffow=arr(i+1)-IntVal
msgbox difffow
If diffback<difffow Then
msgbox arr(i)
Else
If i+1>arrSize Then
msgbox arr(arrSize)
Else
msgbox arr(i+1)
End If
End If
End If
If i+1>=arrSize Then
msgbox ("Come out of for loop")
Exit for
End If
Next
No comments:
Post a Comment