G Graeme Mitchell Active Member Licensed User Mar 12, 2019 #1 I am trying to sort the ListPart list. I tried listpart.sort(true) but it errors out. I checked the whole list to see if there were any anomalies but they are all numbers (2-4 digit) Code: Copy Sub FillArray(Search As Int) If Search < 99 Then partsList = su.LoadCSV(File.DirDocuments, "Database.txt", TAB) Dim MyArray (partsList.size,24) As String listpart.Initialize lastx = partsList.Size -2 For i=0 To partsList.Size -2 Dummy = partsList.Get (i) For j= 0 To 24 MyArray (i,j)= Dummy(j) Next listpart.Add(cs.Initialize.Font(fnt).Append(MyArray(i,Search)).PopAll) Next SearchIndex = Search PickerPart.SetItems(0,listpart) PickerPart.SetRowsHeight(40) End If End Sub
I am trying to sort the ListPart list. I tried listpart.sort(true) but it errors out. I checked the whole list to see if there were any anomalies but they are all numbers (2-4 digit) Code: Copy Sub FillArray(Search As Int) If Search < 99 Then partsList = su.LoadCSV(File.DirDocuments, "Database.txt", TAB) Dim MyArray (partsList.size,24) As String listpart.Initialize lastx = partsList.Size -2 For i=0 To partsList.Size -2 Dummy = partsList.Get (i) For j= 0 To 24 MyArray (i,j)= Dummy(j) Next listpart.Add(cs.Initialize.Font(fnt).Append(MyArray(i,Search)).PopAll) Next SearchIndex = Search PickerPart.SetItems(0,listpart) PickerPart.SetRowsHeight(40) End If End Sub
Erel B4X founder Staff member Licensed User Longtime User Mar 12, 2019 #2 Graeme M itchell said: I tried listpart.sort(true) but it errors out Click to expand... Where is the error message? Where is the relevant code? I don't see any call to Sort. Upvote 0
Graeme M itchell said: I tried listpart.sort(true) but it errors out Click to expand... Where is the error message? Where is the relevant code? I don't see any call to Sort.
G Graeme Mitchell Active Member Licensed User Mar 12, 2019 #3 The sort was just about the SearchIndex = Search line Code: Copy listpart.sort(true) SearchIndex = Search PickerPart.SetItems(0,listpart) PickerPart.SetRowsHeight(40) [\code] Application_Start Application_Active DatabaseFile Was Download Error occurred on line: 157 (Database) -[NSConcreteMutableAttributedString compare:options:]: unrecognized selector sent to instance 0x14751470 Stack Trace: ( CoreFoundation <redacted> + 152 libobjc.A.dylib objc_exception_throw + 38 CoreFoundation <redacted> + 0 CoreFoundation <redacted> + 696 CoreFoundation _CF_forwarding_prep_0 + 24 PartsDatabase __17-[B4IList sort::]_block_invoke_2 + 98 CoreFoundation <redacted> + 50 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation CFSortIndexes + 402 CoreFoundation <redacted> + 316 CoreFoundation <redacted> + 74 PartsDatabase -[B4IList sort::] + 544 PartsDatabase -[B4IList Sort:] + 62 CoreFoundation <redacted> + 68 CoreFoundation <redacted> + 300 PartsDatabase +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784 PartsDatabase -[B4IShell runVoidMethod] + 210 PartsDatabase -[B4IShell raiseEventImpl:method:args::] + 2042 PartsDatabase -[B4IShellBI raiseEvent:event:params:] + 1328 PartsDatabase +[B4IDebug delegate:::] + 52 PartsDatabase -[b4i_database _fillarray:] + 420 PartsDatabase -[b4i_database _show:] + 1384 PartsDatabase -[b4i_main _btnmat_click] + 430 CoreFoundation <redacted> + 68 CoreFoundation <redacted> + 300 PartsDatabase +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784 PartsDatabase -[B4IShell runMethod:] + 588 PartsDatabase -[B4IShell raiseEventImpl:method:args::] + 2192 PartsDatabase -[B4IShellBI raiseEvent:event:params:] + 1328 PartsDatabase __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74 libdispatch.dylib <redacted> + 10 libdispatch.dylib <redacted> + 22 libdispatch.dylib _dispatch_main_queue_callback_4CF + 902 CoreFoundation <redacted> + 8 CoreFoundation <redacted> + 848 CoreFoundation CFRunLoopRunSpecific + 470 CoreFoundation CFRunLoopRunInMode + 104 GraphicsServices GSEventRunModal + 80 UIKit UIApplicationMain + 150 PartsDatabase main + 106 libdyld.dylib <redacted> + 2 ) Class (b4i_httpjob) instance released. Upvote 0
The sort was just about the SearchIndex = Search line Code: Copy listpart.sort(true) SearchIndex = Search PickerPart.SetItems(0,listpart) PickerPart.SetRowsHeight(40) [\code] Application_Start Application_Active DatabaseFile Was Download Error occurred on line: 157 (Database) -[NSConcreteMutableAttributedString compare:options:]: unrecognized selector sent to instance 0x14751470 Stack Trace: ( CoreFoundation <redacted> + 152 libobjc.A.dylib objc_exception_throw + 38 CoreFoundation <redacted> + 0 CoreFoundation <redacted> + 696 CoreFoundation _CF_forwarding_prep_0 + 24 PartsDatabase __17-[B4IList sort::]_block_invoke_2 + 98 CoreFoundation <redacted> + 50 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation <redacted> + 146 CoreFoundation CFSortIndexes + 402 CoreFoundation <redacted> + 316 CoreFoundation <redacted> + 74 PartsDatabase -[B4IList sort::] + 544 PartsDatabase -[B4IList Sort:] + 62 CoreFoundation <redacted> + 68 CoreFoundation <redacted> + 300 PartsDatabase +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784 PartsDatabase -[B4IShell runVoidMethod] + 210 PartsDatabase -[B4IShell raiseEventImpl:method:args::] + 2042 PartsDatabase -[B4IShellBI raiseEvent:event:params:] + 1328 PartsDatabase +[B4IDebug delegate:::] + 52 PartsDatabase -[b4i_database _fillarray:] + 420 PartsDatabase -[b4i_database _show:] + 1384 PartsDatabase -[b4i_main _btnmat_click] + 430 CoreFoundation <redacted> + 68 CoreFoundation <redacted> + 300 PartsDatabase +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1784 PartsDatabase -[B4IShell runMethod:] + 588 PartsDatabase -[B4IShell raiseEventImpl:method:args::] + 2192 PartsDatabase -[B4IShellBI raiseEvent:event:params:] + 1328 PartsDatabase __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74 libdispatch.dylib <redacted> + 10 libdispatch.dylib <redacted> + 22 libdispatch.dylib _dispatch_main_queue_callback_4CF + 902 CoreFoundation <redacted> + 8 CoreFoundation <redacted> + 848 CoreFoundation CFRunLoopRunSpecific + 470 CoreFoundation CFRunLoopRunInMode + 104 GraphicsServices GSEventRunModal + 80 UIKit UIApplicationMain + 150 PartsDatabase main + 106 libdyld.dylib <redacted> + 2 ) Class (b4i_httpjob) instance released.
Erel B4X founder Staff member Licensed User Longtime User Mar 12, 2019 #4 You cannot sort attributed strings or CSBuilders. Use B4XOrderedMap: https://www.b4x.com/android/forum/threads/b4x-b4xcollections-more-collections.101071 Add the regular strings as keys and the CSBuilders as values. Sort the keys and create a new list with the values. Upvote 0
You cannot sort attributed strings or CSBuilders. Use B4XOrderedMap: https://www.b4x.com/android/forum/threads/b4x-b4xcollections-more-collections.101071 Add the regular strings as keys and the CSBuilders as values. Sort the keys and create a new list with the values.
G Graeme Mitchell Active Member Licensed User Mar 12, 2019 #5 So the command to create the OrderedMap is below but I am not sure how to implement this into my for next loop since I am only looking at the adding a numeric value which I assume is the value but what would be the key? The first column in the partsList ir MyArray is a unique identifier but then I tried the code below to add that and I see the warning "Types do not match" Code: Copy From website Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap2(Array("a", "b", "c", "d"), Array(1, 2, 3, 4)) My Code Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap2(MyArray(i,0),MyArray(i,search)) Upvote 0
So the command to create the OrderedMap is below but I am not sure how to implement this into my for next loop since I am only looking at the adding a numeric value which I assume is the value but what would be the key? The first column in the partsList ir MyArray is a unique identifier but then I tried the code below to add that and I see the warning "Types do not match" Code: Copy From website Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap2(Array("a", "b", "c", "d"), Array(1, 2, 3, 4)) My Code Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap2(MyArray(i,0),MyArray(i,search))
Erel B4X founder Staff member Licensed User Longtime User Mar 13, 2019 #6 Something like: Code: Copy Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap For i=0 To partsList.Size -2 Dummy = partsList.Get (i) For j= 0 To 24 MyArray (i,j)= Dummy(j) Next om.Put((MyArray(i,Search), cs.Initialize.Font(fnt).Append(MyArray(i,Search)).PopAll) Next om.Keys.Sort(True) For Each s As String In om.Keys listpart.Add(om.Get(s)) Next Upvote 0
Something like: Code: Copy Dim om As B4XOrderedMap = B4XCollections.CreateOrderedMap For i=0 To partsList.Size -2 Dummy = partsList.Get (i) For j= 0 To 24 MyArray (i,j)= Dummy(j) Next om.Put((MyArray(i,Search), cs.Initialize.Font(fnt).Append(MyArray(i,Search)).PopAll) Next om.Keys.Sort(True) For Each s As String In om.Keys listpart.Add(om.Get(s)) Next
G Graeme Mitchell Active Member Licensed User Mar 18, 2019 #7 Thank you, that worked perfectly Upvote 0