Solved

Create an array of files from commondialog showopen.

Posted on 2000-02-14
15
339 Views
Last Modified: 2010-05-02
I have chosen some files with the commondialog showopen thingy, and have them stored in the CommonDialog1.filename but now I would like them in in array split up, they are all on one line after each other.

HELP!

Tax
0
Comment
Question by:prosit
  • 6
  • 4
  • 4
  • +1
15 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
Using VB6? Use the Split function.
0
 
LVL 7

Expert Comment

by:Vbmaster
Comment Utility
Using VB5? Use something like this..

Function GetRows(TextStr As String, ByRef Rad() As String, ChrLine As String, Optional MaxCount As Integer = 0, Optional RemoveEmptyLines As Boolean) As Long

  Dim RadNr As Long
  Dim TeckenNr As Long
  Dim Tecken As String
 
  If (Len(TextStr) = 0) Then
    ReDim Rad(0)
    GetRows = 0
    Exit Function
  End If
 
  ReDim Rad(10)
  RadNr = 1
  TeckenNr = 0
  TextStr = TextStr
 
  Do Until (TeckenNr >= Len(TextStr))
    TeckenNr = TeckenNr + 1
    Tecken = Mid$(TextStr, TeckenNr, 1)
    If (Tecken = ChrLine) Then
      If (RadNr Mod 10 = 0) Then ReDim Preserve Rad(RadNr + 10)
      RadNr = RadNr + 1
      If (ChrLine = Chr$(13)) Then TeckenNr = TeckenNr + 1
    Else
      If (RadNr = MaxCount) Then
        Rad(RadNr) = Mid$(TextStr, TeckenNr)
        Exit Do
      Else
        Rad(RadNr) = Rad(RadNr) + Tecken
      End If
    End If
  Loop
 
  'Ta bort alla tomma rader
  If RemoveEmptyLines Then
    For RadNr = RadNr To 1 Step -1
      If (Len(Rad(RadNr)) <> 0) Then Exit For
    Next
  End If
  ReDim Preserve Rad(RadNr)
 
  GetRows = RadNr
 
End Function
0
 
LVL 7

Expert Comment

by:Vbmaster
Comment Utility
Forget the function above, this one is much nicer..

Function GetRows2(Text As String, Rad() As String, Divider As String) As Long
 
  Dim RadNr As Long
  Dim TeckenNr As Long
  Dim LenDivider As Long
  Dim OldTeckenNr As Long
 
  RadNr = 0
  OldTeckenNr = 1
  TeckenNr = InStr(Text, Divider)
  LenDivider = Len(Divider)
 
  Do Until (TeckenNr = 0)
    RadNr = RadNr + 1
    ReDim Preserve Rad(RadNr - 1)
    Rad(RadNr - 1) = Mid$(Text, OldTeckenNr, TeckenNr - OldTeckenNr)
    OldTeckenNr = TeckenNr + LenDivider
    TeckenNr = InStr(OldTeckenNr, Text, Divider)
  Loop
 
  If (OldTeckenNr <= Len(Text)) Then
    RadNr = RadNr + 1
    ReDim Preserve Rad(RadNr - 1)
    Rad(RadNr - 1) = Mid$(Text, OldTeckenNr)
  End If
 
  GetRows2 = RadNr
 
End Function

0
 
LVL 2

Author Comment

by:prosit
Comment Utility
It's 6 :)

I'll look at split thanks

T
0
 
LVL 2

Author Comment

by:prosit
Comment Utility
Alright, got the split working, but what's the delimiter in the showopen?  It gives the first "G:\My" the second "documents" and so forth, so I need to decide what's splitting them up.

Any ideas?

J
0
 
LVL 7

Accepted Solution

by:
Vbmaster earned 20 total points
Comment Utility
If you use the GetOpenFileName API to show the FileDialog it's a Chr$(0).
0
 
LVL 2

Author Comment

by:prosit
Comment Utility
What I'm doing now is:

Dim Names() As String

Private Sub Command1_Click()
    With CommonDialog1
        If .CancelError = True Then Exit Sub
        .Flags = cdlOFNHideReadOnly + cdlOFNAllowMultiselect _
                   + cdlOFNExplorer
        .Filter = "Text Files (*.Txt)|*.Txt|"
        .FilterIndex = 1
        .ShowOpen
    End With
    Names = Split(CommonDialog1.FileName)
End Sub

Names = all files on one line, I don't know what delimiter it uses.

The help says it's spaces, but that does not work???

J
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Author Comment

by:prosit
Comment Utility
VB Master you are the man!

Thanks all!

J
0
 
LVL 54

Expert Comment

by:nico5038
Comment Utility
Why using the commondialog-show and splitting afterwards?

I use my own filelist-box, giving control about the way the user can select (single-, multiple-, etc) the files and I have no split problem. Just a test whether ot not an item is selected.
0
 
LVL 54

Expert Comment

by:nico5038
Comment Utility
Why using the commondialog-show and splitting afterwards?

I use my own filelist-box, giving control about the way the user can select (single-, multiple-, etc) the files and I have no split problem. Just a test whether ot not an item is selected.
0
 
LVL 7

Expert Comment

by:Vbmaster
Comment Utility
nico5038: because it looks better, and the user is probably more used to the standard Win9x-look of the dialog. ;)
0
 
LVL 54

Expert Comment

by:nico5038
Comment Utility
Vbmaster: True for the standard windows user. However a multiselect is not often used by average users. I myself used the listbox solution to perform manipulations on the selected files, thus having the possibility to show the progress of the application by scrolling the filelist to the currently processing file.:)
0
 
LVL 2

Author Comment

by:prosit
Comment Utility
nico5038:

Can I take a look at it?

J
0
 
LVL 54

Expert Comment

by:nico5038
Comment Utility
Funch:

Create your own form with the following components:

CommandButton    btnSelectAll
CommonDialog     CommonDialog1
VB.ComboBox      Combo1
VB.DirListBox    Dir1
VB.DriveListBox  Drive1
VB.FileListBox   File1

Add this code behind the form:

Option Explicit
'
' Sample program for "controlled" file selection
'
Private Sub Combo1_Change()
File1.Pattern = Combo1.Text
File1.Refresh
End Sub

Private Sub Combo1_Click()
' Put itemdata in file filter
File1.Pattern = Left(Combo1.List(Combo1.ListIndex), 5)
File1.Refresh
End Sub

Private Sub Drive1_Change()
On Error GoTo Error_Drive1_Change
   
' Set directory path.
Dir1.Path = Drive1.Drive
Error_Drive1_Change:
' Check for errors like "no floppy"
If Err = 68 Then
    MsgBox "This drive is not available"
End If
End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1.Path  ' Set file path.
End Sub
Private Sub Form_Activate()
Form_Load
End Sub

Private Sub Form_Load()
Dim Entry As String          ' Declare variables.
On Error GoTo errorhandling
' Init combobox
    Combo1.Clear
' Fill listbox with default selection
    Combo1.AddItem "*.*     - All files"
    Combo1.AddItem "*.txt   - Text files"
    Combo1.AddItem "*.dll   - Modules  "
    Combo1.ListIndex = 0
errorhandling:
    Select Case Err
    Case 0
        ' No action
    Case Else
        MsgBox "Error: " & Err & " Beschrijving: " & Err.Description
    End Select
End Sub

Private Sub btnSelectAll_Click()
Dim i As Integer
' Toggle between select all and deselect all
' This processing can also be used to reset file under process
If btnSelectAll.Caption = "&Select All" Then
    btnSelectAll.Caption = "&DeSelect All"
    For i = 0 To File1.ListCount - 1    ' Loop through entire list.
        File1.Selected(i) = True        ' Set property of entry
    Next i
    ' This statement is used to reset the listbox to show the first entry
    ' When set to comment, the 'set selected' will scroll the file1 filelistbox
    ' to the bottom
    File1.TopIndex = 0
Else
    btnSelectAll.Caption = "&Select All"
    For i = 0 To File1.ListCount - 1
        File1.Selected(i) = False
    Next i
End If
End Sub

The btnSelect gives one example of processing the filelistbox, but you can ofcourse 'invert' the setting of the entry to the testing of the value set by the user!

Success
0
 
LVL 2

Author Comment

by:prosit
Comment Utility
The selectall does not work in this example, but I get the point.

Thanks

t
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now