home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch08 / mfiles / mfiles95.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-07-03  |  4.7 KB  |  142 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    =   3885
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   6840
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3885
  11.    ScaleWidth      =   6840
  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            =   3015
  25.       TabIndex        =   1
  26.       Top             =   1155
  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            =   180
  42.       TabIndex        =   0
  43.       Top             =   3180
  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          =   450
  81.       Left            =   135
  82.       TabIndex        =   2
  83.       Top             =   510
  84.       Width           =   6555
  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. ' INCREASE THE BUFFER SIZE to 2K
  100. ' (the default size is 256, which may be small for
  101. ' some really long file names)
  102.     CommonDialog1.MaxFileSize = 2 * 1024
  103.     CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
  104.     Label1.Caption = ""
  105.     List1.Clear
  106.     CommonDialog1.Filter = "All Files|*.*"
  107.     CommonDialog1.ShowOpen
  108.     fileNames = CommonDialog1.FileName
  109.     If Len(fileNames) = 0 Then
  110.         MsgBox "No files selected"
  111.         Exit Sub
  112.     End If
  113. ' Extract path name:
  114. ' IF FILETITLE IS NOT EMPTY, THEN A SINGLE FILE
  115. ' HAS BEEN SELECTED. DISPLAY IT AND EXIT
  116.     If CommonDialog1.FileTitle <> "" Then
  117.         List1.AddItem CommonDialog1.FileTitle
  118.         Exit Sub
  119.     End If
  120. ' FILETITLE IS NOT EMPTY, THEN MANY FILES WERE SELECTED
  121. ' AND WE MUST EXTRACT THEM FROM THE FILENAME PROPERTY
  122.     spPosition = InStr(fileNames, Chr(0))
  123.     pathName = Left(fileNames, spPosition - 1)
  124.     Label1.Caption = pathName
  125.     fileNames = Mid(fileNames, spPosition + 1)
  126. ' then extract each space delimited file name
  127.     If Len(fileNames) = 0 Then
  128.         List1.AddItem "No files selected"
  129.         Exit Sub
  130.     Else
  131.         spPosition = InStr(fileNames, Chr(0))
  132.         While spPosition > 0
  133.             List1.AddItem Left(fileNames, spPosition - 1)
  134.             fileNames = Mid(fileNames, spPosition + 1)
  135.             spPosition = InStr(fileNames, Chr(0))
  136.         Wend
  137. ' Add the last file's name to the list
  138. ' (the last file name isn't followed by a space)
  139.         List1.AddItem fileNames
  140.     End If
  141. End Sub
  142.