08-21-2006 03:41 AM
08-21-2006 09:35 AM
Hi sicla,
Personally, I don't like using List files and serial evaluation in DIAdem. I much prefer to use the GetFileName() function to return an array of file paths and loop explicitly over those file paths in a FOR loop, like this:
Hope that helps,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' FileList Dialog.VBS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
OPTION EXPLICIT
Dim i, ExtFilter, FilePaths, Msg
ExtFilter = "(*.csv), *.csv"
ExtFilter = "*.TDM; *.DAT; *.LVM; *.CSV"
ExtFilter = ""
Msg = "Select the data file(s) to load ... Press <Cancel> when finished"
FilePaths = GetFilePaths(AutoActPath, ExtFilter, Msg)
FOR i = 1 TO UBound(FilePaths)
MsgBox FilePaths(i)
NEXT ' i
'-------------------------------------------------------------------------------------
'******* GetFilePaths() *** *** NEW Function ***
'-------------------------------------------------------------------------------------
Function GetFilePaths(DefaultDir, ExtFilter, Msg)
Dim i, k, f, fso, iMax, FileListPath, StartIdx, CurrFiles, FileList
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Promt the User to select the ASCII files to load with a File Dialog
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FileListPath = AutoActPath & "FileDlgList.asc"
Set fso = CreateObject("Scripting.FileSystemObject")
StartIdx = 0
ReDim FileList(0)
FileDlgDir = DefaultDir
Do ' Until (DlgState = "IDCancel")
Call FileNameGet("ANY", "FileRead", FileDlgDir, ExtFilter, FileListPath, 1, Msg)
IF (DlgState = "IDCancel") THEN Exit Do
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Read in the saved list of file(s) selected in the File Dialog into FileList()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set f = fso.OpenTextFile(FileListPath, 1, True) ' f.ReadAll returns file contents
CurrFiles = Split(vbCRLF & f.ReadAll, vbCRLF) ' turn file lines into an array
f.Close ' close the file
iMax = UBound(CurrFiles)
IF iMax > 0 AND Trim(CurrFiles(iMax)) = "" THEN
iMax = iMax - 1
ReDim Preserve CurrFiles(iMax)
END IF
Call BubbleSort(CurrFiles) ' sort the array of file names alphabetically
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Append current file dialog selection(s) to any previous file dialog selection(s)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
IF iMax < 1 THEN iMax = 0
ReDim Preserve FileList(k + iMax)
FOR i = 1 TO iMax
k = k + 1
FileList(k) = CurrFiles(i)
NEXT ' i
Exit Do ' forces only 1 dialog, good if all desired files are in the same folder
Loop ' Until (DlgState = "IDCancel")
GetFilePaths = FileList
End Function ' GetFilePaths()
'-------------------------------------------------------------------------------------
'-- BubbleSort() -- -- NEW SUBROUTINE --
'-------------------------------------------------------------------------------------
Sub BubbleSort(NamesToSort)
Dim i, SwapName, Swapped
Do ' Until bubble sort of NamesToSort() is finished
Swapped = False
FOR i = 1 TO UBound(NamesToSort)-1
IF StrComp(UCase(NamesToSort(i)), UCase(NamesToSort(i+1))) > 0 THEN
SwapName = NamesToSort(i)
NamesToSort(i) = NamesToSort(i+1)
NamesToSort(i+1) = SwapName
Swapped = True
END IF ' Name(i) and Name(i+1) need to be swapped
NEXT ' i
Loop Until NOT (Swapped)
End Sub ' BubbleSort()
08-22-2006 02:41 AM