home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch08 / mfiles / mfiles.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-07-03  |  4.5 KB  |  138 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form MultipleFiles 
  4.    Caption         =   "Multiple File Selection with File Open the Common Dialog Control"
  5.    ClientHeight    =   3720
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   6810
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3720
  11.    ScaleWidth      =   6810
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.ListBox List1 
  14.       BeginProperty Font 
  15.          Name            =   "Verdana"
  16.          Size            =   9
  17.          Charset         =   0
  18.          Weight          =   400
  19.          Underline       =   0   'False
  20.          Italic          =   0   'False
  21.          Strikethrough   =   0   'False
  22.       EndProperty
  23.       Height          =   2580
  24.       Left            =   3030
  25.       TabIndex        =   1
  26.       Top             =   990
  27.       Width           =   3645
  28.    End
  29.    Begin VB.CommandButton Command1 
  30.       Caption         =   "Select Multiple Files"
  31.       BeginProperty Font 
  32.          Name            =   "Verdana"
  33.          Size            =   9.75
  34.          Charset         =   0
  35.          Weight          =   400
  36.          Underline       =   0   'False
  37.          Italic          =   0   'False
  38.          Strikethrough   =   0   'False
  39.       EndProperty
  40.       Height          =   510
  41.       Left            =   165
  42.       TabIndex        =   0
  43.       Top             =   3060
  44.       Width           =   2340
  45.    End
  46.    Begin MSComDlg.CommonDialog CommonDialog1 
  47.       Left            =   1215
  48.       Top             =   1770
  49.       _ExtentX        =   847
  50.       _ExtentY        =   847
  51.       _Version        =   393216
  52.    End
  53.    Begin VB.Label Label2 
  54.       Caption         =   "Selected Path"
  55.       BeginProperty Font 
  56.          Name            =   "Verdana"
  57.          Size            =   9.75
  58.          Charset         =   0
  59.          Weight          =   400
  60.          Underline       =   0   'False
  61.          Italic          =   0   'False
  62.          Strikethrough   =   0   'False
  63.       EndProperty
  64.       Height          =   270
  65.       Left            =   150
  66.       TabIndex        =   3
  67.       Top             =   195
  68.       Width           =   1860
  69.    End
  70.    Begin VB.Label Label1 
  71.       BeginProperty Font 
  72.          Name            =   "Verdana"
  73.          Size            =   9
  74.          Charset         =   0
  75.          Weight          =   400
  76.          Underline       =   0   'False
  77.          Italic          =   0   'False
  78.          Strikethrough   =   0   'False
  79.       EndProperty
  80.       Height          =   330
  81.       Left            =   135
  82.       TabIndex        =   2
  83.       Top             =   480
  84.       Width           =   6195
  85.    End
  86. Attribute VB_Name = "MultipleFiles"
  87. Attribute VB_GlobalNameSpace = False
  88. Attribute VB_Creatable = False
  89. Attribute VB_PredeclaredId = True
  90. Attribute VB_Exposed = False
  91. '  ******************************
  92. '  ******************************
  93. '  ** MASTERING VB6            **
  94. '  ** by Evangelos Petroutos   **
  95. '  ** SYBEX, 1998              **
  96. '  ******************************
  97. '  ******************************
  98. Private Sub Command1_Click()
  99.     CommonDialog1.Flags = cdlOFNAllowMultiselect
  100.     Label1.Caption = ""
  101.     List1.Clear
  102.     CommonDialog1.Filter = "All Files|*.*"
  103.     CommonDialog1.ShowOpen
  104.     filenames = CommonDialog1.FileName
  105.     If Len(filenames) = 0 Then
  106.         MsgBox "No files selected"
  107.         Exit Sub
  108.     End If
  109. ' Extract path name:
  110. ' IF FILETITLE IS NOT EMPTY, THEN A SINGLE FILE
  111. ' HAS BEEN SELECTED. DISPLAY IT AND EXIT
  112.     If CommonDialog1.FileTitle <> "" Then
  113.         List1.AddItem CommonDialog1.FileTitle
  114.         Exit Sub
  115.     End If
  116. ' FILETITLE IS NOT EMPTY, THEN MANY FILES WERE SELECTED
  117. ' AND WE MUST EXTRACT THEM FROM THE FILENAME PROPERTY
  118.     spPosition = InStr(filenames, " ")
  119.     pathName = Left(filenames, spPosition - 1)
  120.     Label1.Caption = pathName
  121.     filenames = Mid(filenames, spPosition + 1)
  122. ' then extract each space delimited file name
  123.     If Len(filenames) = 0 Then
  124.         List1.AddItem "No files selected"
  125.         Exit Sub
  126.     Else
  127.         spPosition = InStr(filenames, " ")
  128.         While spPosition > 0
  129.             List1.AddItem Left(filenames, spPosition - 1)
  130.             filenames = Mid(filenames, spPosition + 1)
  131.             spPosition = InStr(filenames, " ")
  132.         Wend
  133. ' Add the last file's name to the list
  134. ' (the last file name isn't followed by a space)
  135.         List1.AddItem filenames
  136.     End If
  137. End Sub
  138.