question on types
BlitzPlus Forums/BlitzPlus Programming/question on types
| ||
is there a way to locate a specific type in a list of types? for example, rem type type characters field CharNum field Name$ . .other misc fields . end type rem set type list for i=1 to 100 character\characters = new characters character\CharNum = i next rem this is the only way I know to locate a specific character in the list for character.characters = each characters if character\charNum = 50 then character\name$="John" next end Ok, so that's how I locate list entry 50 for example. I don't know if the code works just enter it here off the top of my head but I think you can see what I'm trying to get at. I know you can got to the first, last types by character.characters = FIRST characters character.characters = LAST characters and you can move up or down one place with AFTER and BEFORE character = AFTER character character = BEFORE character but is there someway to go to a specific type record? Thanks, John |
| ||
This is actually one thing that my CollLib v2 UserLib addresses. If you install it you could do something like this: Note that this kind of lookup is very fast and exactly what the StringHashList is built to do. You will not notice any slowdowns when searching even if you have millions of users in the list. |
| ||
but is there someway to go to a specific type record? I'm afraid, no - you have to scan the entire type collection until you find the one that matches your search. Alternatively, if the range of numbers to be searched is reasonable small, you can declare and build up an array of types, and later get the n-element directly using the array index : for n = 0 to 99 character.characters = new characters character\charNum = whatever array_of_character.characters(n) = character next . . 'getting the 5er element is a snap: character.characters = array_of_character(4) Hope this helps, Sergio. |
| ||
ok, thanks. I've fought around with types for some time and I guess it's a matter of when to use what for what type if function. I'll continue to use a multidiminision array for when I need a searchable list. john |