DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort Loaded Groups in Portal According to Source Filename Property

Solved!
Go to solution

Hello,

 

I am using a script to load 4 files in th Data portal and later graph some selected channels. The problem is that when I choose the files through a dialog box, the order gets mixed up in the data portal. I would like the files to be sorted according to the source filename. Here is the loading script:

 

 

Dim i, intLoop, Group,b
Call Data.Root.Clear()
If FileDlgShow(DataReadPath,"TDMS Files,*.tdms","DataSelection",True) = "IDOk" Then
  For i = 0 to UBound(FileDlgNameList) 
Call DataFileLoad(FileDlgNameList(i),"TDMS","Load") DataFilename,FileImportFilter,ImportAction          
Next
End If

 Is there any way I can do that?

 

Thank you!

 

 

 

0 Kudos
Message 1 of 3
(4,377 Views)
Solution
Accepted by topic author Saloutios

Hi Saloutios,

 

You can sort the FileDlgNameList Array for example using the BubbleSort algorithm:

Sub BubbleSort(arr)
    Dim value, numEls
    Dim index
    Dim firstItem
    Dim indexLimit, lastSwap
    ' account for optional arguments
    numEls = UBound(arr)
    firstItem = LBound(arr)
    lastSwap = numEls
    Do
        indexLimit = lastSwap - 1
        lastSwap = 0
        For index = firstItem To indexLimit
            value = arr(index)
            If (value > arr(index + 1)) Then
                ' if the items are not in order, swap them
                arr(index) = arr(index + 1)
                arr(index + 1) = value
                lastSwap = index
            End If
        Next
    Loop While lastSwap
End Sub

The input array is sorted after you called that procedure.

 

Hope this helps

 

Winfried

Message 2 of 3
(4,359 Views)

@winner wrote:

Hi Saloutios,

 

You can sort the FileDlgNameList Array for example using the BubbleSort algorithm:

Sub BubbleSort(arr)
    Dim value, numEls
    Dim index
    Dim firstItem
    Dim indexLimit, lastSwap
    ' account for optional arguments
    numEls = UBound(arr)
    firstItem = LBound(arr)
    lastSwap = numEls
    Do
        indexLimit = lastSwap - 1
        lastSwap = 0
        For index = firstItem To indexLimit
            value = arr(index)
            If (value > arr(index + 1)) Then
                ' if the items are not in order, swap them
                arr(index) = arr(index + 1)
                arr(index + 1) = value
                lastSwap = index
            End If
        Next
    Loop While lastSwap
End Sub

The input array is sorted after you called that procedure.

 

Hope this helps

 

Winfried


Hi Winfried,

 

Thank you very much for the reply. That worked just fine for me!

Cheers!

0 Kudos
Message 3 of 3
(4,341 Views)