home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / pdoxde / fileform.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  11.5 KB  |  310 lines

  1. VERSION 2.00
  2. Begin Form FileForm 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "File Form"
  5.    ClientHeight    =   3735
  6.    ClientLeft      =   1935
  7.    ClientTop       =   1665
  8.    ClientWidth     =   5700
  9.    ControlBox      =   0   'False
  10.    FontBold        =   -1  'True
  11.    FontItalic      =   0   'False
  12.    FontName        =   "System"
  13.    FontSize        =   9.75
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   4140
  17.    Icon            =   0
  18.    Left            =   1875
  19.    LinkMode        =   1  'Source
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    MinButton       =   0   'False
  23.    ScaleHeight     =   3735
  24.    ScaleWidth      =   5700
  25.    Top             =   1320
  26.    Width           =   5820
  27.    Begin DriveListBox DRV_Drives 
  28.       Height          =   315
  29.       Left            =   2895
  30.       TabIndex        =   7
  31.       Top             =   3135
  32.       Width           =   2475
  33.    End
  34.    Begin CommandButton BTN_Cancel 
  35.       Cancel          =   -1  'True
  36.       Caption         =   "Cancel"
  37.       Height          =   420
  38.       Left            =   1560
  39.       TabIndex        =   9
  40.       Top             =   3120
  41.       Width           =   1125
  42.    End
  43.    Begin CommandButton BTN_Ok 
  44.       Caption         =   "OK"
  45.       Default         =   -1  'True
  46.       Height          =   420
  47.       Left            =   240
  48.       TabIndex        =   8
  49.       Top             =   3120
  50.       Width           =   1125
  51.    End
  52.    Begin DirListBox DIR_Dirs 
  53.       Height          =   1880
  54.       Left            =   2910
  55.       TabIndex        =   5
  56.       Top             =   880
  57.       Width           =   2460
  58.    End
  59.    Begin FileListBox FIL_Files 
  60.       Height          =   1785
  61.       Left            =   345
  62.       Pattern         =   "*.db"
  63.       TabIndex        =   2
  64.       Top             =   885
  65.       Width           =   2460
  66.    End
  67.    Begin TextBox TXT_TextBox 
  68.       Height          =   315
  69.       Left            =   210
  70.       TabIndex        =   1
  71.       Text            =   "*.db"
  72.       Top             =   405
  73.       Width           =   2610
  74.    End
  75.    Begin Label LAB_Drives 
  76.       Caption         =   "Dri&ves:"
  77.       Height          =   255
  78.       Left            =   2835
  79.       TabIndex        =   6
  80.       Top             =   2850
  81.       Width           =   765
  82.    End
  83.    Begin Label LAB_CurrentDir 
  84.       Caption         =   "---"
  85.       Height          =   225
  86.       Left            =   2895
  87.       TabIndex        =   4
  88.       Top             =   480
  89.       Width           =   2445
  90.    End
  91.    Begin Label LAB_Directories 
  92.       Caption         =   "&Directories:"
  93.       Height          =   240
  94.       Left            =   2820
  95.       TabIndex        =   3
  96.       Top             =   150
  97.       Width           =   1200
  98.    End
  99.    Begin Label LAB_FileName 
  100.       Caption         =   "File &Name:"
  101.       Height          =   240
  102.       Left            =   120
  103.       TabIndex        =   0
  104.       Top             =   120
  105.       Width           =   1200
  106.    End
  107. Dim LastChange As Integer   'remember what changed last
  108. Sub BTN_Cancel_Click ()
  109.     TXT_TextBox.SetFocus
  110.     FileForm.Hide
  111.     CancelOp = True
  112. End Sub
  113. Sub BTN_OK_Click ()
  114.     Select Case LastChange
  115.         Case 0 To 1             'Text box control was last changed
  116.             LastChange = False
  117.             filespec = TXT_TextBox.text
  118.             If IsFileName(filespec) Then
  119.                 HighLightTextBox
  120.                 FileForm.Hide
  121.             End If
  122.         Case 2               'Directory list control was last changed
  123.             LastChange = False
  124.             DIR_Dirs.path = DIR_Dirs.List(DIR_Dirs.ListIndex)
  125.         End Select
  126.     pdox1.filename.text = filespec
  127. End Sub
  128. Sub DIR_Dirs_Change ()
  129.     ' propogate directory changes to other controls
  130.     FIL_Files.path = DIR_Dirs.path
  131.     LAB_CurrentDir.Caption = DIR_Dirs.path
  132.     ChDir DIR_Dirs.path
  133. End Sub
  134. Sub DIR_Dirs_Click ()
  135.     LastChange = 2  'remember that the DIR_Dirs control changed
  136. End Sub
  137. Sub DRV_Drives_Change ()
  138.     ' change the DIR_Dirs control path, it will
  139.     ' pass the change on to the FIL_Files control
  140.     DIR_Dirs.path = DRV_Drives.Drive
  141.     ChDrive (DRV_Drives.Drive)
  142. End Sub
  143. Sub FIL_Files_Click ()
  144.     'echo the selected name in the Text box
  145.     TXT_TextBox.text = FIL_Files.filename
  146. End Sub
  147. Sub FIL_Files_DblClick ()
  148.     'we have a final selection from the File Save dialog
  149.     TXT_TextBox.text = FIL_Files.filename
  150.     BTN_OK_Click
  151. End Sub
  152. Sub FIL_Files_PathChange ()
  153.     'Show the current search pattern in the TXT_TextBox control
  154.     TXT_TextBox.text = FIL_Files.Pattern
  155.     HighLightTextBox
  156. End Sub
  157. Sub FIL_Files_PatternChange ()
  158.     TXT_TextBox.text = FIL_Files.Pattern
  159.     HighLightTextBox
  160. End Sub
  161. Sub Form_Load ()
  162.     LAB_CurrentDir.Caption = DIR_Dirs.path  'Show full path name in a label
  163.     LastChange = 0                          'No controls have been modified
  164.     DIR_Dirs.Height = FIL_Files.Height      'Align Drives box to Files box
  165. End Sub
  166. Sub Form_Unload (Cancel As Integer)
  167.     Cancel = True   ' Don't unload form, just hide it
  168.     FileForm.Hide
  169.     CancelOp = True ' Notify Cardfile form of cancellation
  170. End Sub
  171. Sub HighLightTextBox ()
  172.     TXT_TextBox.SelStart = 0
  173.     TXT_TextBox.SelLength = Len(TXT_TextBox.text)
  174.     TXT_TextBox.SetFocus
  175. End Sub
  176. Function IsFileName (filespec As String) As Integer
  177. ' This function accepts FileSpec, a string, as input, then
  178. ' checks to see if the string is a valid file path/expression.
  179. ' If FileSpec is valid, and specifies a new drive, pattern and/or
  180. ' directory, the directory and file list boxes are notified.
  181. ' If FileSpec contains a valid file name, the filename is placed
  182. ' in the form's text edit box and IsFileName() returns a value of
  183. ' TRUE.  If FileSpec does not contain a valid file name (ie, it
  184. ' contains directory name and/or a new file pattern and/or an
  185. ' invalid file/path expression), IsFileName() returns FALSE.
  186.     Dim Index As Integer
  187.     Dim OldDir As String
  188.     Dim NewDir As String
  189.     On Local Error Resume Next
  190.     OldDir = CurDir$                    'Remember current directory
  191.     filespec = LCase$(filespec)
  192.     If Mid$(filespec, 2, 1) = ":" Then  'Does it specify new drive?
  193.         ChDrive (filespec)
  194.         DIR_Dirs.path = CurDir$
  195.         If Err Then
  196.             MsgBox Error$(Err), 0, "Disk Error"
  197.             ChDrive (OldDir)
  198.             DIR_Dirs.path = CurDir$
  199.             IsFileName = False
  200.             Exit Function
  201.         Else filespec = Right$(filespec, Len(filespec) - 2)
  202.         End If
  203.     End If
  204.     ChDir (filespec)
  205.     If Err Then                     'Separate path/filename, try again
  206.         While InStr(filespec, "\")      'Parse any directory info
  207.         
  208.             'NewDir gets text to the left of & including FileSpec's first "\"
  209.             NewDir = NewDir + Left$(filespec, InStr(filespec, "\"))
  210.         
  211.             'FileSpec becomes the text to the right of the first "\"
  212.             filespec = Right$(filespec, Len(filespec) - InStr(filespec, "\"))
  213.         Wend
  214.         
  215.         If NewDir <> "" Then
  216.             If Len(NewDir) > 1 Then NewDir = Left$(NewDir, Len(NewDir) - 1)'Remove ending "\"
  217.             Err = 0
  218.             ChDir (NewDir)
  219.             If Err Then
  220.                 MsgBox "Invalid path: '" + NewDir + "'", 0, "Cardfile"
  221.                 IsFileName = False
  222.             Else
  223.                 If ProcessFileSpec(filespec) Then
  224.                     IsFileName = True
  225.                 Else
  226.                     If (InStr(filespec, "*") = 0) And (InStr(filespec, "?") = 0) Then
  227.                         ChDrive (OldDir)
  228.                         ChDir (OldDir)
  229.                     Else
  230.                         DIR_Dirs.path = CurDir$     'Update file controls
  231.                     End If
  232.                     IsFileName = False
  233.                 End If
  234.             End If
  235.         Else
  236.             IsFileName = ProcessFileSpec(filespec)
  237.         End If
  238.     Else
  239.         'User specified a new, valid dir; update the file controls
  240.         DIR_Dirs.path = filespec
  241.     End If
  242. End Function
  243. Function ProcessFileSpec (filespec As String) As Integer
  244. ' This function accepts a string which may be a directory name,
  245. ' a wildcard pattern, or a file name.  The function returns TRUE
  246. ' if the string is a valid filename, and FALSE if the string is
  247. ' either an invalid filename or a directory specification.  If the
  248. ' string specifies a directory, ProcessFileSpec() changes the
  249. ' current directory and updates the appropriate form controls.
  250. ' Note: This procedure expects FileForm's caption to be set to
  251. '       one of "File Save As", "File Open" or "File Merge" in order
  252. '       to prompt the user appropriately (eg - 'Replace existing
  253. '       file?' during File Save As, or "File not found' during
  254. '       File Open/Merge).
  255.     Dim MsgBoxResponse As Integer
  256.     On Local Error Resume Next
  257.     If filespec <> "" Then
  258.         Err = 0
  259.         ChDir (filespec)
  260.         If Err Then     ' FileSpec is a filename or wildcard, not a dir
  261.             If InStr(filespec, ".") = False Then filespec = filespec + ".crd"
  262.             If Len(filespec) > 12 Then
  263.                 MsgBox ("Filename too long: '" + filespec + "'")
  264.                 ProcessFileSpec = False
  265.             Else
  266.                 'Did user specify a new wildcard pattern?
  267.                 If InStr(filespec, "*") Or InStr(filespec, "?") Then
  268.                     FIL_Files.Pattern = filespec
  269.                     ProcessFileSpec = False
  270.                 Else
  271.                     If filespec <> ".." Then
  272.                         ' We're finished -- got a valid filename
  273.                             If Dir$(filespec) = "" Then
  274.                                 If FileForm.Caption = "File Open" Or FileForm.Caption = "File Merge" Then
  275.                                     MsgBox "No such file: " + filespec, 0, "Cardfile"
  276.                                     ProcessFileSpec = False
  277.                                 Else
  278.                                     TXT_TextBox.text = filespec
  279.                                     ProcessFileSpec = True
  280.                                 End If
  281.                             Else
  282.                                 If FileForm.Caption = "File Save As" Then
  283.                                     MsgBoxResponse = MsgBox("Replace existing " + filespec + "?", 4 + 32 + 256, "Cardfile")
  284.                                     If MsgBoxResponse = MB_YES Then
  285.                                         Kill filespec
  286.                                         TXT_TextBox.text = filespec
  287.                                         ProcessFileSpec = True
  288.                                     Else
  289.                                         ProcessFileSpec = False
  290.                                     End If
  291.                                 Else
  292.                                     TXT_TextBox.text = filespec
  293.                                     ProcessFileSpec = True
  294.                                 End If
  295.                             End If
  296.                         End If
  297.                     End If
  298.                 End If
  299.         Else   ' FileSpec was just a directory name
  300.             ProcessFileSpec = False
  301.         End If
  302.     Else
  303.         ' The user only specified a new drive (handled in IsFileName)
  304.         ProcessFileSpec = False
  305.     End If
  306. End Function
  307. Sub TXT_TextBox_Change ()
  308.     LastChange = 1
  309. End Sub
  310.