Having a brainfart with a listbox

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • If I have a list box with

    1
    2
    3
    4
    5
    6

    and I only want to remove the last X amount of items, how do I do with a loop ?
    So if X = 2
    the result is
    1
    2
    3
    4

    I was thinking about

    Start loop "deletelines" 2 times

    on loop "deletelines"
    - Listbox: Delete LoopIndex("deletelines") - 2
    or
    - Listbox: Delete 2 - LoopIndex("deletelines")
    or
    List Nb Lines( "checklist" ) - LoopIndex("deletelines")

    but none of them work


    but that ain't it..

    Anyone able to resolve my brainfart?

    Thanks :)

  • Make sure the list object is set to 0 index in the properties. Always delete the bottom line. Retrieve the number of list items to find it. When you delete a line, the length of the list is reduced by 1, and so is the index of the last item.

  • Hi Perry, this is from the list help file.

    Sort. If checked, the entries of the list will be sorted in alphabetical order.

    1-based index. If not checked, the first line of the list will have number 0. If checked, it will have number 1. This is a personal choice of yours. Programmers usually choose 0 based indexes.

    Add a Line
    The Add a Line action adds a line of text to the bottom of the List object.

    Insert a Line
    The Insert a Line action inserts a line of text into the List object. Note: if you use -1 as index (or 0 if the indexes begin from 1), the line is added to the end of the list.

    I personaly test the total line number to the start delete line number, thus deleting the remainder of line numbers, stopping when total equals start +1 /- 1.

  • That lists are sorted alphabetically, and not numerically, is an important point if your list enters double-digits.
    It means for example, that "10" will be sorted ahead of "2", because "1" comes before "2" - unless you manually add leading zeroes (ie. make it "02").

    The easy way (for positive integers) is to say:

    right$( "00" + str$( value ), 3)

    ...where the number on the right (3) is the desired number of digits, and the number of zeroes in the string is one less than that.

    Fortunately, CF2.5's val() function will ignore leading zeroes, so getting the original number out of the list again is not a problem.

    If you ever need a method that works for floats as well as integers, you will need to add both leading and trailing zeroes (you can use "len( str$(val mod 1))" to get the number of digits after the decimal point), or use multiplication to shift the decimal point, and then ignore everything after.


  • Thanks.

    I use Insert Line "1" , 0
    I use Insert Line "2" , 0
    I use Insert Line "3" , 0

    when it's checked I get

    1
    2
    3

    but unchecked it is

    3
    2
    1

  • [MENTION=15247]Perry[/MENTION]. Yes, I get the same result because the insert line number is always 0 (zero) on all three. Insert Line "1" , 0; Insert Line "2" , 0; Insert Line "3" , 0. Always inserting at line number 0 gives that result which gives the appearance of being backwards.

    Insert a Line
    The Insert a Line action inserts a line of text into the List object. Note: if you use -1 as index (or 0 if the indexes begin from 1), the line is added to the end of the list.

    But if 1-base index is unchecked, the insert line number start should be 0, and cheched 1. For some reason it still works.

    Sequencial line numbering: If checked it works if I used sequencial line numbering starting at line 1, Insert Line "1" , 1; Insert Line "2" , 2; Insert Line "3" , 3. If unchecked it did not work. I had to change the starting line to 0 (zero) Insert Line "1" , 0; Insert Line "2" , 1; Insert Line "3" , 2.

    Hope this helps, and it is a mind bender :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!