home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / swbback / selectdi.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-05-12  |  13.9 KB  |  400 lines

  1. VERSION 5.00
  2. Begin VB.Form SelectDirForm 
  3.    AutoRedraw      =   -1  'True
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Select Files"
  6.    ClientHeight    =   4170
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   6420
  10.    Icon            =   "SelectDirForm.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4170
  15.    ScaleWidth      =   6420
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   1  'CenterOwner
  18.    Begin VB.Frame Frame2 
  19.       Caption         =   "Include Files in this Date Range"
  20.       Height          =   1215
  21.       Left            =   3390
  22.       TabIndex        =   15
  23.       Top             =   2040
  24.       Width           =   2925
  25.       Begin VB.TextBox EndDate 
  26.          Height          =   315
  27.          Left            =   810
  28.          TabIndex        =   9
  29.          Top             =   690
  30.          Width           =   1725
  31.       End
  32.       Begin VB.TextBox StartDate 
  33.          Height          =   315
  34.          Left            =   810
  35.          TabIndex        =   8
  36.          Top             =   330
  37.          Width           =   1725
  38.       End
  39.       Begin VB.Label Label3 
  40.          AutoSize        =   -1  'True
  41.          Caption         =   "To"
  42.          Height          =   195
  43.          Left            =   360
  44.          TabIndex        =   17
  45.          Top             =   750
  46.          Width           =   195
  47.       End
  48.       Begin VB.Label Label1 
  49.          AutoSize        =   -1  'True
  50.          Caption         =   "From"
  51.          Height          =   195
  52.          Left            =   360
  53.          TabIndex        =   16
  54.          Top             =   390
  55.          Width           =   345
  56.       End
  57.    End
  58.    Begin VB.TextBox SelPath 
  59.       Height          =   315
  60.       Left            =   600
  61.       TabIndex        =   0
  62.       Top             =   180
  63.       Width           =   5715
  64.    End
  65.    Begin VB.CheckBox DoSubDirs 
  66.       Caption         =   "&Process subdirectories of this path"
  67.       Height          =   225
  68.       Left            =   3450
  69.       TabIndex        =   10
  70.       Top             =   3330
  71.       Value           =   1  'Checked
  72.       Width           =   2865
  73.    End
  74.    Begin VB.Frame Frame1 
  75.       Caption         =   "Include Files with these Attributes"
  76.       Height          =   1305
  77.       Left            =   3390
  78.       TabIndex        =   13
  79.       Top             =   690
  80.       Width           =   2925
  81.       Begin VB.CheckBox InclAttributes 
  82.          Caption         =   "&Hidden"
  83.          Height          =   225
  84.          Index           =   2
  85.          Left            =   270
  86.          TabIndex        =   5
  87.          Tag             =   "2"
  88.          Top             =   900
  89.          Value           =   1  'Checked
  90.          Width           =   1230
  91.       End
  92.       Begin VB.CheckBox InclAttributes 
  93.          Caption         =   "&Archive"
  94.          Height          =   225
  95.          Index           =   4
  96.          Left            =   1650
  97.          TabIndex        =   7
  98.          Tag             =   "32"
  99.          Top             =   645
  100.          Value           =   1  'Checked
  101.          Width           =   1020
  102.       End
  103.       Begin VB.CheckBox InclAttributes 
  104.          Caption         =   "&System"
  105.          Height          =   195
  106.          Index           =   3
  107.          Left            =   1650
  108.          TabIndex        =   6
  109.          Tag             =   "4"
  110.          Top             =   390
  111.          Value           =   1  'Checked
  112.          Width           =   1050
  113.       End
  114.       Begin VB.CheckBox InclAttributes 
  115.          Caption         =   "&Read Only"
  116.          Height          =   225
  117.          Index           =   1
  118.          Left            =   270
  119.          TabIndex        =   4
  120.          Tag             =   "1"
  121.          Top             =   645
  122.          Value           =   1  'Checked
  123.          Width           =   1230
  124.       End
  125.       Begin VB.CheckBox InclAttributes 
  126.          Caption         =   "&Normal"
  127.          Height          =   225
  128.          Index           =   0
  129.          Left            =   270
  130.          TabIndex        =   3
  131.          Tag             =   "0"
  132.          Top             =   390
  133.          Value           =   1  'Checked
  134.          Width           =   1230
  135.       End
  136.    End
  137.    Begin VB.CommandButton CancelBtn 
  138.       Cancel          =   -1  'True
  139.       Caption         =   "&Cancel"
  140.       Height          =   360
  141.       Left            =   5190
  142.       TabIndex        =   12
  143.       Top             =   3750
  144.       Width           =   1125
  145.    End
  146.    Begin VB.CommandButton OKBtn 
  147.       Caption         =   "&OK"
  148.       Default         =   -1  'True
  149.       Height          =   360
  150.       Left            =   3930
  151.       TabIndex        =   11
  152.       Top             =   3750
  153.       Width           =   1125
  154.    End
  155.    Begin VB.DirListBox Dir 
  156.       Height          =   3015
  157.       Left            =   120
  158.       TabIndex        =   1
  159.       Top             =   720
  160.       Width           =   3135
  161.    End
  162.    Begin VB.DriveListBox Drive 
  163.       Height          =   315
  164.       Left            =   120
  165.       TabIndex        =   2
  166.       Top             =   3780
  167.       Width           =   3135
  168.    End
  169.    Begin VB.Label Label2 
  170.       AutoSize        =   -1  'True
  171.       Caption         =   "Path"
  172.       Height          =   195
  173.       Left            =   150
  174.       TabIndex        =   14
  175.       Top             =   240
  176.       Width           =   330
  177.    End
  178. Attribute VB_Name = "SelectDirForm"
  179. Attribute VB_GlobalNameSpace = False
  180. Attribute VB_Creatable = False
  181. Attribute VB_PredeclaredId = True
  182. Attribute VB_Exposed = False
  183. Option Explicit
  184. Private mModalResult As VbMsgBoxResult      'How did the user leave this form (OK/Cancel)?
  185. Private mSelectedDir As String              'Directory selected in the directory list.
  186. Private mAttributes As Long                 'File attributes selected.
  187. Private mDoSubDirs As Boolean               'Process subdirectories?
  188. Private mFullPath As String                 'Full path and file mask specified.
  189. Private mStartDate As Date                  'Start date for date range of files to process.
  190. Private mEndDate As Date                    'End date for date range of files to process.
  191. '#####################################################
  192. '                 PUBLIC PROPERTIES
  193. '#####################################################
  194. Public Property Get ModalResult() As VbMsgBoxResult
  195.     ModalResult = mModalResult
  196. End Property
  197. Public Property Let Attributes(vData As Long)
  198.     mAttributes = vData
  199. End Property
  200. Public Property Get Attributes() As Long
  201.     Attributes = mAttributes
  202. End Property
  203. Public Property Let ProcessSubDirs(vData As Boolean)
  204.     mDoSubDirs = vData
  205. End Property
  206. Public Property Get ProcessSubDirs() As Boolean
  207.     ProcessSubDirs = mDoSubDirs
  208. End Property
  209. Public Property Let FullPathMask(vData As String)
  210.     mFullPath = vData
  211. End Property
  212. Public Property Get FullPathMask() As String
  213.     FullPathMask = mFullPath
  214. End Property
  215. Public Property Let StartingDate(vData As String)
  216.     mStartDate = vData
  217. End Property
  218. Public Property Get StartingDate() As String
  219.     StartingDate = mStartDate
  220. End Property
  221. Public Property Let EndingDate(vData As String)
  222.     mEndDate = vData
  223. End Property
  224. Public Property Get EndingDate() As String
  225.     EndingDate = mEndDate
  226. End Property
  227. '#####################################################
  228. '                 PUBLIC METHODS
  229. '#####################################################
  230. '------------------------------------------
  231. '  Public sub to default options for a
  232. '  new file spec.
  233. '------------------------------------------
  234. Public Sub DefaultOptions()
  235.     mSelectedDir = CurDir
  236.     If (Right$(mSelectedDir, 1) <> "\") Then mSelectedDir = mSelectedDir & "\"
  237.     Dir.Path = mSelectedDir
  238.     mFullPath = mSelectedDir & "*.*"
  239.     SelPath.Text = mFullPath
  240.     Drive.Drive = Left$(mFullPath, 2)
  241.     mStartDate = CDate("Jan 1 1900")
  242.     mEndDate = CDate("Dec 31 9999")
  243.     StartDate.Text = Format("Jan 1 1900", "m/d/yyyy")
  244.     EndDate.Text = Format("Dec 31 9999", "m/d/yyyy")
  245.     mDoSubDirs = True
  246.     DoSubDirs.Value = vbChecked
  247.     mAttributes = vbNormal + vbReadOnly + vbHidden + vbSystem + vbArchive
  248.     SetAttributes
  249. End Sub
  250. '#####################################################
  251. '                 PRIVATE ROUTINES
  252. '#####################################################
  253. '------------------------------------------
  254. '  User canceled this form.
  255. '------------------------------------------
  256. Private Sub CancelBtn_Click()
  257.     Unload Me
  258. End Sub
  259. '------------------------------------------
  260. '  Change to the directory list.
  261. '------------------------------------------
  262. Private Sub Dir_Click()
  263.     'Update the currently selected directory variable,
  264.     'as well as the entire path text box.
  265.     'As the user selects a new directory in the list,
  266.     'we update the complete file spec edit box with the
  267.     'currently selected directory, while retaining the
  268.     'file mask that was entered (MakeFullPath function).
  269.     mSelectedDir = Dir.List(Dir.ListIndex)
  270.     SelPath.Text = MakeFullPath
  271. End Sub
  272. '------------------------------------------
  273. '  Change to the drive list.
  274. '------------------------------------------
  275. Private Sub Drive_Change()
  276.     Screen.MousePointer = vbHourglass
  277.     Dir.Path = Drive.Drive
  278.     Screen.MousePointer = vbDefault
  279. End Sub
  280. '------------------------------------------
  281. '  Form startup event.
  282. '------------------------------------------
  283. Private Sub Form_Activate()
  284.     On Error Resume Next
  285.     'Assume a cancellation of this form.
  286.     mModalResult = vbCancel
  287.     'Set the controls to the form properties.
  288.     'If this form was started from an Add button,
  289.     'the properties were probably defaulted by calling
  290.     'the DefaultOptions method of this form from the calling
  291.     'form.  If this was launched by an Edit button, the
  292.     'properties should have been initialized to the
  293.     'selections for the file spec highlighted in the list.
  294.     Dir.Path = mSelectedDir
  295.     SelPath.Text = mFullPath
  296.     Drive.Drive = Left$(mSelectedDir, 2)
  297.     StartDate.Text = Format(mStartDate, "m/d/yyyy")
  298.     EndDate.Text = Format(mEndDate, "m/d/yyyy")
  299.     Dir.Path = ExtractFilePath(SelPath.Text)
  300.     If (mDoSubDirs = True) Then
  301.         DoSubDirs.Value = vbChecked
  302.     Else
  303.         DoSubDirs.Value = vbUnchecked
  304.     End If
  305.     'Parse the Long Int of attributes and set the
  306.     'proper checkboxes for each bit.
  307.     SetAttributes
  308.     SelPath.SetFocus
  309.     SelPath.SelStart = 0
  310.     SelPath.SelLength = Len(SelPath.Text)
  311. End Sub
  312. '------------------------------------------
  313. '  Accept the form options (OK button).
  314. '------------------------------------------
  315. Private Sub OKBtn_Click()
  316.     'Validate the dates.  DateTime picker was not used to
  317.     'avoid dependencies on the (huge) Common Controls OCXs.
  318.     If (Not IsDate(StartDate.Text)) Then
  319.         MsgBox "The starting date is not a valid date.", vbExclamation + vbOKOnly, "Invalid Date"
  320.         Exit Sub
  321.     End If
  322.     If (Not IsDate(EndDate.Text)) Then
  323.         MsgBox "The ending date is not a valid date.", vbExclamation + vbOKOnly, "Invalid Date"
  324.         Exit Sub
  325.     End If
  326.     'Fix-up the path edit box and add a drive if missing.
  327.     If (InStr(SelPath.Text, ":") = 0) And (Left$(SelPath.Text, 2) <> "\\") Then
  328.         If (Left$(SelPath.Text, 1) = "\") Then
  329.             SelPath.Text = Left$(Drive.Drive, 2) & SelPath.Text
  330.         Else
  331.             SelPath.Text = Left$(Drive.Drive, 2) & "\" & SelPath.Text
  332.         End If
  333.     End If
  334.     'Set public properties for the caller.
  335.     mModalResult = vbOK
  336.     mDoSubDirs = (DoSubDirs.Value = vbChecked)
  337.     mSelectedDir = ExtractFilePath(SelPath.Text)
  338.     mFullPath = MakeFullPath
  339.     mStartDate = CDate(StartDate.Text)
  340.     mEndDate = CDate(EndDate.Text)
  341.     'Make a Long Int out of the property checkboxes.
  342.     MakeAttributeLong
  343.     Unload Me
  344. End Sub
  345. '------------------------------------------
  346. '  Make a long integer attribute bitmask
  347. '  based on the options selected.
  348. '------------------------------------------
  349. Private Sub MakeAttributeLong()
  350.     Dim C As CheckBox
  351.     mAttributes = 0
  352.     For Each C In InclAttributes
  353.         If (C.Value = vbChecked) Then mAttributes = mAttributes + CInt(C.Tag)
  354.     Next C
  355. End Sub
  356. '------------------------------------------
  357. '  Set the checkboxes based on the
  358. '  options selected in the Long Int
  359. '  bitmask.
  360. '------------------------------------------
  361. Private Sub SetAttributes()
  362.     Dim C As CheckBox
  363.     For Each C In InclAttributes
  364.         If ((mAttributes And C.Tag) = C.Tag) Then
  365.             C.Value = vbChecked
  366.         Else
  367.             C.Value = vbUnchecked
  368.         End If
  369.     Next C
  370. End Sub
  371. '------------------------------------------
  372. '  Create a complete path and file spec
  373. '  based on the currently selected
  374. '  directory and the existing file mask
  375. '  portion of the path in the path edit
  376. '  box.
  377. '------------------------------------------
  378. Private Function MakeFullPath() As String
  379.     Dim RetPath As String
  380.     Dim PathName As String
  381.     Dim FileName As String
  382.     PathName = mSelectedDir
  383.     FileName = Trim(ExtractFileName(SelPath.Text))
  384.     If (FileName = "") Then FileName = "*.*"
  385.     If (Right$(PathName, 1) = "\") Then
  386.         RetPath = PathName & FileName
  387.     Else
  388.         RetPath = PathName & "\" & FileName
  389.     End If
  390.     If (InStr(mSelectedDir, ":") = 0) And (Left$(mSelectedDir, 2) <> "\\") Then RetPath = Left$(Drive.Drive, 2) & RetPath
  391.     MakeFullPath = RetPath
  392. End Function
  393. '------------------------------------------
  394. '  Select the text in the path edit box.
  395. '------------------------------------------
  396. Private Sub SelPath_GotFocus()
  397.     SelPath.SelStart = 0
  398.     SelPath.SelLength = Len(SelPath.Text)
  399. End Sub
  400.