Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:18 10 Mar 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Greetings from Spain and a possible bug in MMBasic

Author Message
Fede
Newbie

Joined: 09/03/2026
Location: Spain
Posts: 5
Posted: 02:13pm 09 Mar 2026
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 11032
Posted: 02:32pm 09 Mar 2026
Copy link to clipboard 
Print this post

Hi

Welcome to the forum. I think the sort is doing what is intended. From the manual

  Quote  It has an optional parameter ‘indexarray%()’. If used this must be an integer
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.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3666
Posted: 03:52pm 09 Mar 2026
Copy link to clipboard 
Print this post

  matherp said  
  Quote  It has an optional parameter ‘indexarray%()’. If used this must be an integer array of the same size as the array to be sorted. After the sort this array willcontain the original index position of each element in the array being sorted
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)?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS
 
Fede
Newbie

Joined: 09/03/2026
Location: Spain
Posts: 5
Posted: 04:48pm 09 Mar 2026
Copy link to clipboard 
Print this post

  matherp said  Hi

Welcome to the forum. I think the sort is doing what is intended. From the manual

  Quote  It has an optional parameter ‘indexarray%()’. If used this must be an integer
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: Spain
Posts: 5
Posted: 04:54pm 09 Mar 2026
Copy link to clipboard 
Print this post

  lizby said  
  matherp said  
  Quote  It has an optional parameter ‘indexarray%()’. If used this must be an integer array of the same size as the array to be sorted. After the sort this array willcontain the original index position of each element in the array being sorted
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: Spain
Posts: 5
Posted: 04:55pm 09 Mar 2026
Copy link to clipboard 
Print this post

I'm sorry, but I don't understand you very well, even with the translator.  
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3666
Posted: 05:49pm 09 Mar 2026
Copy link to clipboard 
Print this post

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: Germany
Posts: 1057
Posted: 06:30pm 09 Mar 2026
Copy link to clipboard 
Print this post

@Fede:

You can try DEEPL as a translator / Puedes probar DEEPL como traductor:

https://www.deepl.com

Frank
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026