- Nov 12, 2011--- In ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
>

Thanks for all replies to my question!

> I've got a database where each record is indexed with an alpha-code

> from 'aaa' to 'zzz'...I want to find out if there is a gap in a

> sorted list of these codes...

@Rod

> Treat them as 3-digit radix-26 numbers, and check the numerical

I understand that diodeom's solution is based on something like that where the numeric value of each character is determined by ^$StrPos$ and a string from a to z.

> difference between two records. If not =1, something's missing.

@Axel

> Get the first triple, say pqf and add it to the first line with

Wittily, indeed! But we know from experience that this would lead to a lot of cursor movements, insertings etc ending in a very slow performance with a long list.

> a space...

@diodeom

> The following basic take looks for what the next index in sequence

Thanks, that's great! The advantage is that it needs no '^$Calc$' functions which are rather slow when being called very often.

> should be and flags a gap if no match is found...

Just for the fun of it, I would like to present my first approach. It's dealing with a pure list of 3-digit-alpha-codes from 'aaa' to 'zzz' without any further stuff in the lines.

It's quite fast as well since it doesn't move from line to line but assigns the whole list to an array. The result is a list of codes with gaps, i.e. codes that do not immediately follow one another displayed in a second window (avoid empty line at end of list):

; Assign whole list to array %Codes%

^!SetListDelimiter ^%NL%

^!SetArray %Codes%=^$GetText$

^!Set %i%=1

:Loop

; Assign first and second code to array %A% and %B%

^!Set %A%=^%Codes^%i%%

^!Inc %i%

^!Set %B%=^%Codes^%i%%

; Calculate numeric value of each code

^!Set %x%=^$Calc(^$CharToDec(^$StrIndex(^%A%;1)$)$+^$CharToDec(^$StrIndex(^%A%;2)$)$+^$CharToDec(^$StrIndex(^%A%;3)$)$)$

^!Set %y%=^$Calc(^$CharToDec(^$StrIndex(^%B%;1)$)$+^$CharToDec(^$StrIndex(^%B%;2)$)$+^$CharToDec(^$StrIndex(^%B%;3)$)$)$

; Calculate difference

^!Set %Diff%=^$Calc(^%y%-^%x%)$

^!If ^%Diff% = 1 Skip Else Next

^!If ^%Diff%=-24 Next Else Error

^!If ^%i%=^%Codes0% Out

^!Goto Loop

:Error

; Assign wrong sequence to variable %Gaps%

^!Set %Gaps%=^%Gaps%^%A%/^%B%^P

^!If ^%i%=^%Codes0% Out

^!Goto Loop

:Out

^!IfEmpty ^%Gaps% Next Else Skip_2

^!Info No gaps!

^!Goto End

^!Toolbar New Document

^!InsertText There's a gap at:^P^%Gaps%

^!Toolbar Second Window

^!ClearVariables

Regards,

Flo - << Previous post in topic Next post in topic >>