DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Using UseFileList - problem

Hi, I have searched the forums and another post partly solved my problem, but...
 
I wish to multiple-convert several files from one format to another.   The code works perfectly one one file, but am having problems with multiple files.  I am using UseFileList to create a file.lst listing all the selected files.
 
The problem I get is that the code runs through the correct amount of times (ie the number of files selected), but just does it for the first file....ie the program is not selecting the next file correctly and this first selected file is overwriten with the same data.
 
Here's some of the code, and any help would be greatly appreciated:
 
*****************1st file ********************
Call DataDelAll ' clear all DATA channels
Call FileNameGet("Any","FileRead", "*.tdm", "",AutoActPath & "File", True) 'Dialog box for entering filename
If (DlgState = "IDOk") Then 'Close dialog box with OK
Call ScriptStart(AutoActPath & "File.vbs")
Else
Call MsgBoxDisp("Data loading terminated!")
continue = false
End If
**********************************************
 
 
**************2nd file************************************************
Call DataDelAll ' clear all DATA channels...stops the file being loaded into current file's data portal
Call ASCIILOAD (UseFileList,0)   'calls the file.lst

Call DATAFILELOAD(FileDlgName)  'loads whatever data file is selected
 
'Saving Process
 
Call DATASAVE(FileDlgName +  ".dat", "ANSI") 'saving the dat file in ANSI mode
 
**************************************************
 
many thanks
0 Kudos
Message 1 of 3
(3,141 Views)

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()

0 Kudos
Message 2 of 3
(3,135 Views)
many thanks for your time, thats just what I wanted really
0 Kudos
Message 3 of 3
(3,122 Views)