## _Lee_'s Profile User Rating:

Reputation: 1 Apprentice
Group:
New Members
Active Posts:
5 (0.01 per day)
Joined:
13-December 11
Profile Views:
106
Last Active:
Dec 20 2011 01:16 PM
Currently:
Offline

### Previous Fields

Country:
LV
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Who Cares
Dream Kudos:
0
_Lee_ has not set their status

1. #### In Topic: VBA insertion sort

Posted 20 Dec 2011

here's the code. I'm not sure if it completely qualifies as binary insertion sort, but seems to at least work right:

```Option Explicit
Dim A(1 To 1000) As Integer 'for the unsorted list
Dim B(0 To 1000) As Integer 'for the sorted list
Dim i As Integer, chk As Integer, ef As Integer, poz As Integer, k As Integer

Sub gobinaryagain()

Open "C:\Documents and Settings\Administrator\Desktop\binary.txt" For Input As #1 'where the unsorted list should be read from

ef = 0

Do
ef = ef + 1
Input #1, A(ef)
B(ef) = 32767
Loop Until eof(1)

Close #1

B(0) = 0
B(ef + 1) = 32767

k = 0

Do
k = k + 1
chk = k
poz = chk / 2

Do
chk = chk / 2

If chk = 0 Then
chk = 1
End If

If A(k) > B(poz) Then
poz = poz + chk
ElseIf A(k) < B(poz) Then
poz = poz - chk
ElseIf A(k) = B(poz) Then
Exit Do
Else
MsgBox "Kļūda"
End If

Loop Until A(k) > B(poz) And A(k) < B(poz + 1)

If poz = 0 Then
For i = k To 1 Step -1
B(i + 1) = B(i)
Next i
B(1) = A(k)
ElseIf B(poz) <> 32767 Then
For i = k To poz + 1 Step -1
B(i + 1) = B(i)
Next i
B(poz + 1) = A(k)
ElseIf B(poz) = 32767 Then
B(poz) = A(k)
Else
MsgBox ("Kļūda")
End If

Loop Until k = ef

Open "C:\Documents and Settings\Administrator\Desktop\binary_rez.txt" For Output As #2 'where the sorted list should be printed

For i = 1 To ef
Print #2, B(i)
Next i

Close #2

End Sub

```
2. #### In Topic: VBA insertion sort

Posted 19 Dec 2011

I finally got the code right!
I'll post it here a little later in case anyone else is looking for something like that!
3. #### In Topic: VBA insertion sort

Posted 15 Dec 2011

so I noticed, thanks anyway maj3091, link 2 is very good, but unfortunately doesn't have the code I need

and BobRodes, since I don't understand C++ it might be difficult translating from it.

anyway, I figured someone might have a code an idea what am I doing wrong, but looks like I'll just keep working on it until I get it right
4. #### In Topic: VBA insertion sort

Posted 13 Dec 2011

thanks, but if it was that simple I would have found that or written it myself...

since I'm not a native english speaker, I probably didn't translate the name of this algorithm right- binary insertion sort could be correct... and the best google gives by that search is a code in C++

### My Information

Member Title:
Age:
Age Unknown
Birthday:
July 18
Gender:
Interests:
IT, music
Years Programming:
2
Programming Languages:
VBA, HTML

E-mail:
Private