For Each d As xojo.Core.DictionaryEntry In Dictionary Sorting issue

Hello Guys,

The For Each loop it sorts the data alphabetically in the dictionary ? is there a way to stop that ?

It seems that the new dictionary is messing my data , i`m using the following code to store data and fetch data from Dictionary and in the end its always messed up so i need to rely on the record number that they were added and not on the name sorting

For example i have the following array

Result(xx, aa, bb)

while running the code i get the first loop trough aa instead of xx

[code] dim result As String
dim items() As String

	For Each d As xojo.Core.DictionaryEntry In SearchDict
			Dim name As String = d.Key
			items.Append(name)
	Next
	
	result = Join(items, "|")
	
	Return result[/code]

So my result instead of being xx|aa|bb it becomes aa|bb|xx

I put break points and on the first time i access the method it reaches on the point of For Each d … and the first d.Key that comes is aa, but in the Dictionary aa is record 1 not 0

What you recommend on this ?

The problem is that i`m relying on the data that i input for some custom lists and they must be in order, messing the data by sorting them alphabetically it will ruin all the records .

I was thinking instead of using Dictionaries to use in memory database and populate some temporary tables and do all the processing and sorting , is is more recommended than dictionaries if this is an issue ?

Thanks for the advices.

Xojo.Core.Dictionary

… unordered …

[quote=319538:@Eli Ott]Xojo.Core.Dictionary

… unordered …[/quote]
Well that`s my point as well, but still , why i get that ordering ?

you are not guaranteed that items will come out of a dictionary object in any particular order…

even a database will not guarantee an order… unless it is sorted (ORDER BY), but that seems not what you want either

unordered… means you have no control … it doesn’t mean that perchance it won’t be ordered… it depends on the data entered and how the hashing algoritim deals with it…

[quote=319542:@Dave S]you are not guaranteed that items will come out of a dictionary object in any particular order…

even a database will not guarantee an order… unless it is sorted (ORDER BY), but that seems not what you want either

unordered… means you have no control … it doesn’t mean that perchance it won’t be ordered… it depends on the data entered and how the hashing algoritim deals with it…[/quote]
Thanks Dave,

Well i could set as a reference the record id which is auto incremented and in this way i sort according to that and populate the list with the accurate data so i guess it`s more safe than a dictionary , the issue is that are some specific data that must be in order , messing that order can end up to a lot of mess in that process and by having that it makes the app useless. so i must get it right.

Thanks again.

then you should use something that DOES make assurances about “if you put things into it in this order you get them back in that same order”

like an array

[quote=319548:@Norman Palardy]then you should use something that DOES make assurances about “if you put things into it in this order you get them back in that same order”

like an array[/quote]
Thanks Norman , so , i should store the array in a Dictionary or use Array only to replace the dictionary ? and how do i handle the search then ? i need to validate that data is there, why im using that is because i have to lists and to avoid duplicates, so i have master list that holds the data and the search list that filters the data from master and shows only the available data , then once the data is selected from search list it gets moved via the dictionary in the master list, in this way i keep a track of it, so how i can do that wit the arrays ? i should do a custom code to iterate them and to map and search ? not more easy with a table ?

or i guess i can do a scan of the array and then an if statement and process the data.

Thanks again .

sounds like you need to do a bit more research on how dictionary vs array vs database works… It is hard for any of us to decide which method (or combination) might fit your design best.

You can use IndexOf to check if a value exists in an array.

That will allow you to avoid duplicates in an array.
Thought admittedly, I’m not fully grasping what you are trying to do.