× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Merry Christmas again... May your Christmas joy last longer than a GO SAVE
21.

I have finally written a program tha uses bsearch.  I am seeing a variance
between how it is supposed to work (in the Sorcerer's Guide), and how it is
working for me anyways.

It states that (p 130), if no match was found, a NULL pointer is returned.
In the program I have written, if no match is found, it instead returns a
poiter to another element, that doesn't match the first element (perhaps the
last element it inspected?).

I have debugged it, and I see where it continually calls my finder
subprocedure, and when it finds that there is no match, it doesn't return a
null pointer.  It returns a pointer to another element that is unequal.  I
can get around this, by "pointing" a field at the argument that it returns,
and testing for equality, but before I hard-code a work-around, I wanted to
get your collective opinions.  Here is the code:

The subproc that bsearch calls back:

     P ElemFind        B
     D ElemFind        PI            10I 0
     D  ElemCheckFor                   *   Value
     D  ElemCandidate                  *   Value

     D Element1        S             12A   Based(ElemCheckFor)
     D Element2        S             12A   Based(ElemCandidate)
     D ElemStatus      S             10I 0 Inz

      /Free
       Select;
         When Element1 < Element2;
           ElemStatus = -1;
         When Element2 > Element2;
           ElemStatus = 1;
         Other;
           ElemStatus = 0;
       EndSl;

       Return ElemStatus;
      /End-Free
     P ElemFind        E

The subprocedure that calls bsearch:

     P CheckUpdate     B
     D CheckUpdate     PI              N
     D  Acronym                       3A   Const
     D  Family                        9P 0 Const

     D ElemSig         DS                  Qualified Inz
     D  Acro                          3A
     D  Fam                           9A
     D pElemSig        S               *   Inz(%Addr(ElemSig))
     D WasItFound      S               N   Inz
     D pShowMe         S               *   Inz
     D ShowMe          S             12A   Based(pShowMe)

      /Free
       ElemSig.Acro = Acronym;
       ElemSig.Fam  = %EditC(Family : 'X');

       pShowMe = FindIt( pElemSig  :
                  pUserSpace       :
                  cUpdatedFam      :
                  12               :
                  %PAddr(ElemFind));
       If pShowMe = *Null;
          WasItFound = *Off;
       Else;
          WasItFound = *On;
       EndIf;

       Return WasItFound;
      /End-Free
     P CheckUpdate     E

In the above code, I only mapped the ShowMe variables to see what element it
was returning a pointer to.

So basically, I just need to know if an element exists in the user space.  I
call the CheckUpdate proc, with the two parms, which in turn calls FindIt
(which is the bsearch Prototype), and I always get a *On indicator from
CheckUpdate -- whether the element exists or not.

--
"Enter any 11-digit prime number to continue..."
"In Hebrew SQL, how do you use right() and left()?..." - Random Thought
"If all you have is a hammer, all your problems begin to look like nails"

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.