VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 7005 ClientLeft = 60 ClientTop = 450 ClientWidth = 9885 LinkTopic = "Form1" ScaleHeight = 7005 ScaleWidth = 9885 StartUpPosition = 3 'Windows Default Begin VB.CommandButton Command2 Caption = "Sorted" Height = 975 Left = 5520 TabIndex = 2 Top = 1440 Width = 3495 End Begin VB.CommandButton Command1 Caption = "Command1" Height = 975 Left = 5520 TabIndex = 1 Top = 2640 Width = 3495 End Begin VB.ListBox List1 Height = 3960 Left = 360 TabIndex = 0 Top = 960 Width = 3735 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click() Dim notfound As Boolean notfound = False endpoint = List1.ListCount - 1 startpoint = 0 checkpoint = Val((endpoint + startpoint) \ 2) Target = Val(InputBox("Enter:")) If List1.List(checkpoint) = Target Then MsgBox "target found at" & checkpoint + 1 List1.ListIndex = checkpoint Else Do While Not Val(List1.List(checkpoint)) = Val(Target) If Val(startpoint) > Val(endpoint) Then MsgBox "target not found" Exit Do End If If Val(Target) > Val(List1.List(checkpoint)) Then startpoint = checkpoint + 1 checkpoint = Val((endpoint + startpoint) \ 2) End If If Val(Target) < Val(List1.List(checkpoint)) Then endpoint = checkpoint - 1 checkpoint = Val((endpoint + startpoint) \ 2) End If If Target = List1.List(checkpoint) Then MsgBox "Target found at :" & checkpoint List1.ListIndex = checkpoint Exit Do End If Loop End If End Sub Private Sub Command2_Click() For b = 0 To List1.ListCount - 2 For c = 0 To List1.ListCount - 2 If Val(List1.List(c)) > Val(List1.List(c + 1)) Then t = List1.List(c) List1.List(c) = List1.List(c + 1) List1.List(c + 1) = t End If Next Next End Sub Private Sub Form_Load() For a = 1 To 100 Randomize List1.AddItem Int(1000 * Rnd()) Next End Sub