home *** CD-ROM | disk | FTP | other *** search
/ Dr. CD ROM (Annual Premium Edition) / premium.zip / premium / REFERENC / NIVBSRC.ZIP / SELFILE.FRM < prev    next >
Text File  |  1993-06-02  |  10KB  |  323 lines

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