Hi John, here below the code (credits to René's idea).
In essence: 1) create a temporary datastore for storing columns' name and x, 2) fill the DS scanning the columns, 3) sort DS by x.
Cheers,
Marco
datastore lds_temp
String ls_err, ls_colname
Long i, ll_colx
// Build a temporary DataStore for column sorting
lds_temp = CREATE datastore
String ls_dsdef = 'release 12.6; datawindow() table(column=(type=char(30) name=colname dbname="colname") column=(type=number name=colx dbname="colx"))'
lds_temp.CREATE(ls_dsdef, ls_err)
// Insert Column name and x
For i = 1 To Integer(object.datawindow.column.count)
ll_colx = Long(Describe('#' + String(i) + '.x'))
ls_colname = String(Describe('#' + String(i) + '.Name'))
lds_temp.InsertRow(0)
lds_temp.SetItem(i, 'colname', ls_colname)
lds_temp.SetItem(i, 'colx', ll_colx)
Next
// Sort by x
lds_temp.SetSort("colx ASC")
lds_temp.Sort()
// Display
For i = 1 To lds_temp.RowCount()
MessageBox("Position: " + String(i), "Name: " + lds_temp.GetItemString(i, 'colname'))
Next
DESTROY lds_temp