FileDlgShow Returns Wrong Order of File Selection

Updated Mar 1, 2018

Reported In

Software

  • DIAdem 2015 Base
  • DIAdem 2015 Advanced
  • DIAdem 2015 Professional

Issue Details

I am creating a Script in DIAdem that opens the file selection window by calling FileDlgShow. I select multiple files by holding the control key. Afterwards I want to work with the files by reading the variable FileDlgNameList, which contains the selected files:


I noticed that the order of the files in FileDlgNameList differs from my order of selection: the first file I selected is the last element stored in the result list. The list begins with the second selected file.

For example the script above returns messageboxes in the following order: 
  1. C:\Users\[...]\file2.tdm
  2. C:\Users\[...]\file3.tdm
  3. C:\Users\[...]\file1.tdm
However I selected file1.tdm first and selected file2.tdm and file3.tdm afterwards.

How can I get the correct order of my file selection with FileDlgNameList?

Solution

By calling FileDlgShow DIAdem calls a Windows function that returns the user selection and DIAdem stores that result in FileDlgNameList. DIAdem has no influence on the way how and in which order the file selection will be returned by Windows.

Alternatives to work with the correct order files:
  • Before iterating through the list of files in FileDlgNameList pick the last element of FileDlgNameList that is actually the first one with the UBound function: FileDlgNameList(Ubound(FileDlgNameList))
  • In case your selection matches an alphabetical or numerical order you can sort FileDlgNameList. Other Users already posted their approach of sorting in the NI forum.

WAS THIS ARTICLE HELPFUL?

Not Helpful