|
Forum Index : Microcontroller and PC projects : Greetings from Spain and a possible bug in MMBasic
| Author | Message | ||||
| Fede Newbie Joined: 09/03/2026 Location: SpainPosts: 5 |
Greetings from Spain. A few months ago I bought a PicoCalc and in my free time I've been doing some work on MMBasic. While searching for information on how to update MMBasic and following the trail, I came across your forums. First of all: I'm very grateful for the work done on MMBasic and everything surrounding it, that it's free and that we can all enjoy it. After learning about the controversies surrounding PicoCalc updates, I thought it was quite wrong, so I ordered parts to build a PicoMite VGA. But things are moving slowly; apparently, the war in the Middle East has delayed shipments from China. Meanwhile, I'm working on another 'File Manager', which I'll publish as soon as I have something decent. I'm doing it on the PicoCalc using MMEDIT, a program I also appreciate and find very useful. The issue is that it found a 'bug'. Executing the 'Sort' command a second time on the same array corrupts the sort order created by the first command in the associated index file. Let me explain, or at least try to. If I do this to sort the array into two parts, it doesn't work. SORT DTemp$(),DTempi%(),6,1,nDir SORT DTemp$(),DTempi%(),6,nDir+1 The first command executes correctly, but the second corrupts the sort order created by the first command in DTempi%(). The first part, which shouldn't be affected, reverts to its original ascending sort order. However, DTemp$() is correctly sorted. To make it work, I have to do it like this: 'Ordeno directorios IF nDir>0 then FOR nCont = 1 to nDir DTemp$(nCont) = Alias$(nCont) DTempi%(nCont)=Index%(nCont) NEXT nCont SORT DTemp$(),DTempi%(),6 FOR nCont = 1 to nDir Index%(nCont)=DTempi%(nCont) NEXT nCont ENDIF 'Ordeno Ficheros IF nFile>0 then FOR nCont = 1 to nFile FTemp$(nCont) = Alias$(nDir+nCont) FTempi%(nCont)=Index%(nDir+nCont) NEXT nCont SORT FTemp$(),FTempi%(),6 FOR nCont = 1 to nFile Index%(nDir+nCont)=FTempi%(nCont)+nDir NEXT nCont endif I'm using version ...v6.00.02 RC23 If this bug has already been reported, or if it's not a bug but a feature, I sincerely apologize. Best regards again. (Translated by Google. It's not very good with English.) |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11032 |
Hi Welcome to the forum. I think the sort is doing what is intended. From the manual The code as written always writes values 0 to n-1 (or 1 to n if option base is set) before doing the sort and the index is therefore always just relevant to the last sort done. This may not be what you want but if it is working as I describe it is doing what was intended. |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3666 |
Is this so that you can build an array of keys (from, say, an array of structures), and when you sort the keys, the ‘indexarray%()’ will point you to the original structure element (or other element of an array or set of arrays)? PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS |
||||
| Fede Newbie Joined: 09/03/2026 Location: SpainPosts: 5 |
Welcome to the forum. I think the sort is doing what is intended. From the manual array of the same size as the array to be sorted. After the sort this array will contain the original index position of each element in the array being sorted before it was sorted. Any data in the array will be overwritten. This allows connected arrays to be sorted. The code as written always writes values 0 to n-1 (or 1 to n if option base is set) before doing the sort and the index is therefore always just relevant to the last sort done. This may not be what you want but if it is working as I describe it is doing what was intended. I don't understand you very well, but thank you. |
||||
| Fede Newbie Joined: 09/03/2026 Location: SpainPosts: 5 |
before it was sorted Is this so that you can build an array of keys (from, say, an array of structures), and when you sort the keys, the ‘indexarray%()’ will point you to the original structure element (or other element of an array or set of arrays)? I have an array where the first n elements are directories and the n+1 elements to the end are files. I simply want them to be sorted alphabetically within their respective ranges. DTemp$() are the names and DTempi%() are the indices. They are both the same size. |
||||
| Fede Newbie Joined: 09/03/2026 Location: SpainPosts: 5 |
I'm sorry, but I don't understand you very well, even with the translator. |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3666 |
I think you're saying that you want the file sorted on two different fields--whatever signifies directory or file, and then in order within those categories. I don't think that is possible with sort on the picomite. If you want that in a single file, you might have to separate the directories and sort them, then sort the files, then combine the two. There are some other possibilities, but they all involve additional steps. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS |
||||
| Frank N. Furter Guru Joined: 28/05/2012 Location: GermanyPosts: 1057 |
@Fede: You can try DEEPL as a translator / Puedes probar DEEPL como traductor: https://www.deepl.com Frank |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |