Find a null character in a string of filenames

Hi
I am using the common dialog control to open images. If there is a list of images this works fine using

 With frmtools.cdg_main
        .InitDir = initpath  'set the initial path
        .filename = ""  'rest the file name
        .Filter = "TIFF(.tif.TIF) *.tif|*.tif;|Windows Bitmap *.bmp| *.bmp;|Jpeg (.jpg,JPEG)*.jpg |*.jpg;|JPG 2000 (.jp2,jpf) *.jp2| *.jp2|" 'filter selection for available image types
        .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer  ' enable multiselect
        .CancelError = True 'set the cancel error
        .ShowOpen  'display the open dialog
        filname = .filename
    End With
   


 ' Each file are separated by a null char( chr$(0)  )
 
   filearray = Split(filname, Chr$(0))
       
    ' display the list of the selected files

    For i = LBound(filearray) + 1 To UBound(filearray)
   
        ' the first element is the path
        ' the others are the file name
       
        new_filepath = filearray(0) & "\" & filearray(i)
        ret = IpWsLoad(new_filepath, "")
       
    Next
   
   frmtools.cdg_main.Flags = 0 'reset the file open command

But if there is only one image it does nothing. As this is separated by a null char how can i tell if this char exists to tell if there is more tahn one file name. This does return the single finename so if i can tell between the two i can execute the different code

Thanks
eneateAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
danaseamanConnect With a Mentor Commented:
Try this:

Private Sub Command1_Click()
   Dim fName            As String
   Dim fPath            As String
   Dim fArray()         As String
   Dim i                As Long

   With frmTools.cdg_main
      .InitDir = App.Path 'initpath  'set the initial path
      .FileName = ""  'rest the file name
      .Filter = "TIFF(.tif.TIF) *.tif|*.tif;|Windows Bitmap *.bmp| *.bmp;|Jpeg (.jpg,JPEG)*.jpg |*.jpg;|JPG 2000 (.jp2,jpf) *.jp2| *.jp2|" 'filter selection for available image types
      .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer  ' enable multiselect
      .CancelError = True 'set the cancel error
      .ShowOpen  'display the open dialog
      fName = .FileName
   End With

   ' Each file are separated by a null char( chr$(0)  )

   fArray = Split(fName, Chr$(0))

   ' display the list of the selected files
   If UBound(fArray) = 0 Then
      fPath = fArray(0)
      Debug.Print fPath
   Else
      For i = LBound(fArray) + 1 To UBound(fArray)
         ' the first element is the path
         ' the others are the file name
         fPath = fArray(0) & "\" & fArray(i)
         Debug.Print fPath
         'ret = IpWsLoad(fPath, "")
      Next
   End If
   frmTools.cdg_main.Flags = 0 'reset the file open command
End Sub

Open in new window

0
 
eneateAuthor Commented:
Thanks, works perfectly
0
All Courses

From novice to tech pro — start learning today.