Collection library

Discussion in 'Additional Libraries' started by agraham, Jan 30, 2008.

  1. agraham

    agraham Expert Licensed User

    I assume you are using the db2000GetInfoDevice library. As I pointed out in my post above Basic4ppc v6.9 fundamentally changed the handling of variables, both regular ones and arrays. In order to work with version 6.9 the library would need to be recompiled to return a value of type String[] instead of the type Array that it does now.

    I realise that although I have modified the Collections library to work with Basic4ppc v6.9 I forgot to post the updated library. I'll do that when I've checked it out again.
  2. agraham

    agraham Expert Licensed User

    Basic4ppc version 6.90 significantly changed how variables are handled as it introduced typed variables. Version 1.5 of this library makes some required changes to ArraysEx and ArrayListEx to accommodate this.

    ArrayLists, like all the other collections in Basic4ppc and this library hold their values as strings. Note that arrays are not collection objects in .NET but are more primitive structures that hold the types of values for which they are declared.

    Owing to the changes made to array variables in Basic4ppc v6.90 the optimising compiler requires ArrayList.ToArray to return an array of the same type as that being assigned to, with the ArrayList contents coerced to that type. The ArrayListEx.ToStringArray, ToIntegerArray and ToNumberArray methods are provided to return the type of array required.

    For the same reason ArraysEx now also provides CloneString, CloneInteger and CloneNumber that also return the array types that the optimising compiler requires.

    ArrayListEx.CopyTo will now work with arrays of type Integer, Int32, Number, Double and String.
  3. konisek

    konisek Member Licensed User

    To Agraham:
    Please, will you re-compile the db2000GetInfoDevice library soon, or shall I downgrade to 6.8 version? Thanks, L.
  4. agraham

    agraham Expert Licensed User

    It is not my library to recompile, it was written by maXim. You could try a workaround with the Door library. I haven't tested it but it should (famous last words!) work.

    ObjArray is a Door library ObjectArray.
    ObjArray.New1(0' size doesn't matter as we overwrite the value property
       ObjArray.Value =
       Info0 = ObjArray.Get(
    0' 0 to 4
  5. konisek

    konisek Member Licensed User

    Ok, your code works but I still need the "db2000 GetInfoDevice.dll library", right? So I cannot compile it in v6.9 until maXim revises it. (L)
  6. mjcoon

    mjcoon Well-Known Member Licensed User

    Query & Crash in ArraysExDemoInteger.sbp

    I haven't made much use of Collections.dll but have what I tought would be an ideal use of BinarySearch.

    But I don't even understand the Help. It says
    I think the "it" is
    referring to a negative number returned for a mismatch. But since index values start from zero and index zero could contain a larger number than the search term, a zero result could be ambiguous. Is this correct; does a zero result have to be tested to see if it is a match or not?

    I wondered if I could learn from running ArraysExDemoInteger.sbp, but under the desktop IDE it crashed per the thumbnail.


    Attached Files:

  7. agraham

    agraham Expert Licensed User

    It looks like "cIntegers" is a victim of find and replace when converting ArraysExDemoNumber. :sign0161: It should be "cNumbers".

    I didn't pick that up as I keep Tools -> Check for unassigned... unchecked so it worked for me.
  8. agraham

    agraham Expert Licensed User

    No, it's not correct but I am puzzled as the help is largely copied from the .NET documentation. I suspect that there was an error in the original .NET documentation which is now corrected.

    ArrayList.BinarySearch Method (Object) (System.Collections)
  9. mjcoon

    mjcoon Well-Known Member Licensed User

    Thank you for your instant response, Andrew.

    I guess I shall have to grapple with complements after decades (I remember there were ones-complement and twos-complement). The bitwise complement of zero is not zero; I think that it is the same as -1. But I was definitely getting zero as a value even though there was no hit.

    I have tried changing to use IndexOf() since it should just work slightly slower on a sorted array. But I was getting an index equal to the count of entries, which should not be possible.

    So still baffled. That is even withut the crash with the demo program.

    BTW I wonder why the "next" in the text that you quoted (and gave the source for). Next from where? Surely they mean "first element", not next?

  10. agraham

    agraham Expert Licensed User

    Haven't got time to look at "next" at the moment but
    If index < 0 then
        index = 
    1 - index ' complement
    End If
  11. mjcoon

    mjcoon Well-Known Member Licensed User

    Thanks again; that was my conclusion too! But I was not negating or complementing the result. Merely testing for " > -1" which should have trapped all mismatches but didn't.

    Please ignore my winge about IndexOf(); that problem was down to my not noticing that the order of arguments is quite different from BinarySearch()
  12. agraham

    agraham Expert Licensed User

    Sorry, the perils of haste :(, dinner was ready to serve! The above is wrong, it should be

    If index < 0 then
        index = 
    0 - 1 - index ' complement
    End If
    0xffff (-1) => 0
    0xfffe (-2) => 1
    0cfffd (-3) => 2
    Last edited: Feb 1, 2012
  13. mjcoon

    mjcoon Well-Known Member Licensed User

    Thanks again Andrew. It would be nice to have this explained in the Help, but maybe it is not worth doing that now it is enshrined in this relevant thread.

    None of the above explains why I am getting zero returned from BinarySearch() whereas IndexOf() gives the results I expect and works fine. The demo program works OK if tweaked to look for missing values. BTW I think that the constants are singular as in the Help, not cNumbers. I suppose if you have the detection suppressed this means you will get a null string or zero passed to the operation instead of the intended constant, which could give strange results.

    My look-up arrays are generated by sparsely storing a counter, so are sorted numerically from the outset; I do not perform a sort operation. If you wanted(?) to investigate I could write out a sample array. (It is derived from zooming an OS-GB vector road-map.)


    Attached Files:

  14. agraham

    agraham Expert Licensed User

    Time dims the memory. :( All is now clear! Unfortunately there is a bug in ArraysEx.BinarySearch and ArrayListEx.BinarySearch. The .NET documentation is correct but in attempting to make this statement in the help true
    and notionally make things simpler by compensating for the bitwise inversion I missed that zero would be rturned both for a match at index 0 and for a no match when all the elements are larger than the search value. So as you suggested earlier a zero return is ambiguous and needs a further check doing to be correctly interpreted.
  15. asmag

    asmag Member Licensed User

    How do I use it?


    How do I use it? I pasted the dll library folder but it does not appear in Referenced Libraries


  16. Erel

    Erel Administrator Staff Member Licensed User

    This is a Basic4ppc library, not Basic4android.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice