Vb 6.0

I have done the following code for binary search.But all the time Its showing match not found even if the number is present in the array😔

Dim a As Integer
Dim i, j, k As Integer
Dim numbers(20) As Integer

Private Sub Command1_Click()
j = InputBox(" enter the number of elements in the array")
For i = 0 To j - 1
k = InputBox("enter the number:")
numbers(i) = k
Next i
MsgBox ("numbers successfully inserted")
a = InputBox("enter the number to be searched")
search12 (a)
End Sub

Private Function search12(b As Integer)
Dim Min As Integer
Dim Max As Integer
Dim Mid As Integer
Min = 0
Max = UBound(numbers)
Do While Min <= Max
Mid = Int((Min + Max) / 2)
If b = numbers(Mid) Then
' we have a match
MsgBox ("match found")
Exit Function
ElseIf b < numbers(Mid) Then
Max = Mid - 1
ElseIf b > numbers(Mid) Then
Min = Mid + 1
End If
Loop
'If (Min > Max) Then
' if we get here, the state was not found ...
MsgBox ("match not found")
'End If
Exit Function
End Function

Replies

  • Manish Goyal
    Manish Goyal
    Can you post any example input for this program?
    Here i mean array
  • whiz.kid.aniket
    whiz.kid.aniket
    @samaira are you using ActiveX dll?
  • samaira
    samaira
    whiz.kid.aniket
    @samaira are you using ActiveX dll?
    no m not using activex dll
  • samaira
    samaira
    goyal420
    Can you post any example input for this program?
    Here i mean array
    like e.g i gave input as 1,2,3,4,5,6 for n=6 and searched for 3
  • Manish Goyal
    Manish Goyal
    Do 1 thing
    remove last condition
    and add print statement or whatever used in vb to display output in order to display value of mid and tell me the output

You are reading an archived discussion.

Related Posts

Hello friend's, Many of engineering college student have girl friends. But there is also some student who doesn't(Reason most of the student have EGO problem he didn't like to start...
I am using Mozilla Firefox and i am not able chat on CE-Conference Chat. My mouse pointer doesn't change into cursor. Try to fix the problem.
I have new Micromax MMX 300C EVDO modem from BSNL. It works perfectly in windows platform. Username (cdma) & password (cdma) is also correct which allows to connect to internet....
i am giving a supply to a system where in place of U,V,W supply i am giving U,U,V supply to a system what will be the vectorial current representation of...
Hello, Every body Esp. "CE - Newbie" could you help me devloping remot controler I am A computer Science student and now I am pursuing my MSc in Prague If...