home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_1 / NIVB_SRC / SELFILE.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-06-02  |  9.7 KB  |  280 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. Dim LastChange As Integer   'remember what changed last
  103. Sub CancelButton_Click ()
  104.     Unload SelectFileForm
  105. End Sub
  106. Sub DirBox_Change ()
  107.     ' propogate directory changes to other controls
  108.     FileListBox.Path = DirBox.Path
  109.     CurrDirLabel.Caption = DirBox.Path
  110.     ChDir DirBox.Path
  111. End Sub
  112. Sub DirBox_Click ()
  113.     LastChange = 2  'remember that the DirBox control changed
  114. End Sub
  115. Sub DriveBox_Change ()
  116.     ' change the DirBox control path, it will
  117.     ' pass the change on to the FileListBox control
  118.     DirBox.Path = DriveBox.Drive
  119.     ChDrive (DriveBox.Drive)
  120. End Sub
  121. Sub FileListBox_Click ()
  122.     'echo the selected name in the Text box
  123.     FileNameBox.Text = FileListBox.FileName
  124. End Sub
  125. Sub FileListBox_DblClick ()
  126.     'we have a final selection from the File Save dialog
  127.     FileNameBox.Text = FileListBox.FileName
  128.     OKButton_Click
  129. End Sub
  130. Sub FileListBox_PathChange ()
  131.     'Show the current search pattern in the FileNameBox control
  132.     FileNameBox.Text = FileListBox.Pattern
  133.     HighLightTextBox
  134. End Sub
  135. Sub FileListBox_PatternChange ()
  136.     FileNameBox.Text = FileListBox.Pattern
  137.     HighLightTextBox
  138. End Sub
  139. Sub FileNameBox_Change ()
  140.     LastChange = 1
  141. End Sub
  142. Sub Form_Load ()
  143.     If (currentForm = AFP_FORM) Then
  144.         Unload AFPForm
  145.     End If
  146.     CurrDirLabel.Caption = DirBox.Path  'Show full path name in a label
  147.     LastChange = 0                          'No controls have been modified
  148.     DirBox.Height = FileListBox.Height      'Align Drives box to Files box
  149. End Sub
  150. Sub HighLightTextBox ()
  151.     FileNameBox.SelStart = 0
  152.     FileNameBox.SelLength = Len(FileNameBox.Text)
  153.     FileNameBox.SetFocus
  154. End Sub
  155. Function IsFileName (FileSpec As String) As Integer
  156. ' This function accepts FileSpec, a string, as input, then
  157. ' checks to see if the string is a valid file path/expression.
  158. ' If FileSpec is valid, and specifies a new drive, pattern and/or
  159. ' directory, the directory and file list boxes are notified.
  160. ' If FileSpec contains a valid file name, the filename is placed
  161. ' in the form's text edit box and IsFileName() returns a value of
  162. ' TRUE.  If FileSpec does not contain a valid file name (ie, it
  163. ' contains directory name and/or a new file pattern and/or an
  164. ' invalid file/path expression), IsFileName() returns FALSE.
  165.     Dim Index As Integer
  166.     Dim OldDir As String
  167.     Dim NewDir As String
  168.     On Local Error Resume Next
  169.     OldDir = CurDir$                    'Remember current directory
  170.     FileSpec = LCase$(FileSpec)
  171.     If Mid$(FileSpec, 2, 1) = ":" Then  'Does it specify new drive?
  172.         ChDrive (FileSpec)
  173.         DirBox.Path = CurDir$
  174.         If Err Then
  175.             MsgBox Error$(Err), 0, "Disk Error"
  176.             ChDrive (OldDir)
  177.             DirBox.Path = CurDir$
  178.             IsFileName = False
  179.             Exit Function
  180.         Else FileSpec = Right$(FileSpec, Len(FileSpec) - 2)
  181.         End If
  182.     End If
  183.     ChDir (FileSpec)
  184.     If Err Then                     'Separate path/filename, try again
  185.         While InStr(FileSpec, "\")      'Parse any directory info
  186.         
  187.             'NewDir gets text to the left of & including FileSpec's first "\"
  188.             NewDir = NewDir + Left$(FileSpec, InStr(FileSpec, "\"))
  189.         
  190.             'FileSpec becomes the text to the right of the first "\"
  191.             FileSpec = Right$(FileSpec, Len(FileSpec) - InStr(FileSpec, "\"))
  192.         Wend
  193.         
  194.         If NewDir <> "" Then
  195.             If Len(NewDir) > 1 Then NewDir = Left$(NewDir, Len(NewDir) - 1)'Remove ending "\"
  196.             Err = 0
  197.             ChDir (NewDir)
  198.             If Err Then
  199.                 MsgBox "Invalid path: '" + NewDir + "'", 0, "Cardfile"
  200.                 IsFileName = False
  201.             Else
  202.                 If ProcessFileSpec(FileSpec) Then
  203.                     IsFileName = True
  204.                 Else
  205.                     If (InStr(FileSpec, "*") = 0) And (InStr(FileSpec, "?") = 0) Then
  206.                         ChDrive (OldDir)
  207.                         ChDir (OldDir)
  208.                     Else
  209.                         DirBox.Path = CurDir$     'Update file controls
  210.                     End If
  211.                     IsFileName = False
  212.                 End If
  213.             End If
  214.         Else
  215.             IsFileName = ProcessFileSpec(FileSpec)
  216.         End If
  217.     Else
  218.         'User specified a new, valid dir; update the file controls
  219.         DirBox.Path = FileSpec
  220.     End If
  221. End Function
  222. Sub OKButton_Click ()
  223.     Dim FileSpec As String
  224.     Select Case LastChange
  225.         Case 0 To 1             'Text box control was last changed
  226.             LastChange = False
  227.             FileSpec = FileNameBox.Text
  228.             If IsFileName(FileSpec) Then
  229.                 HighLightTextBox
  230.                 SelectFileForm.Hide
  231.                 If (currentForm = AFP_FORM) Then
  232.                     AFPInfoForm.Show
  233.                 Else
  234.                     FileInfoForm.Show
  235.                 End If
  236.             End If
  237.         Case 2               'Directory list control was last changed
  238.             LastChange = False
  239.             DirBox.Path = DirBox.List(DirBox.ListIndex)
  240.         End Select
  241. End Sub
  242. Function ProcessFileSpec (FileSpec As String) As Integer
  243. ' This function accepts a string which may be a directory name,
  244. ' a wildcard pattern, or a file name.  The function returns TRUE
  245. ' if the string is a valid filename, and FALSE if the string is
  246. ' either an invalid filename or a directory specification.  If the
  247. ' string specifies a directory, ProcessFileSpec() changes the
  248. ' current directory and updates the appropriate form controls.
  249.     Dim MsgBoxResponse As Integer
  250.     On Local Error Resume Next
  251.     If FileSpec <> "" Then
  252.         Err = 0
  253.         ChDir (FileSpec)
  254.         If Err Then     ' FileSpec is a filename or wildcard, not a dir
  255.             'If InStr(FileSpec, ".") = False Then FileSpec = FileSpec + ".crd"
  256.             If Len(FileSpec) > 12 Then
  257.                 MsgBox ("Filename too long: '" + FileSpec + "'")
  258.                 ProcessFileSpec = False
  259.             Else
  260.                 'Did user specify a new wildcard pattern?
  261.                 If InStr(FileSpec, "*") Or InStr(FileSpec, "?") Then
  262.                     FileListBox.Pattern = FileSpec
  263.                     ProcessFileSpec = False
  264.                 Else
  265.                     If FileSpec <> ".." Then
  266.                         ' We're finished -- got a valid filename
  267.                         FileNameBox.Text = FileSpec
  268.                         ProcessFileSpec = True
  269.                     End If
  270.                 End If
  271.             End If
  272.         Else   ' FileSpec was just a directory name
  273.             ProcessFileSpec = False
  274.         End If
  275.     Else
  276.         ' The user only specified a new drive (handled in IsFileName)
  277.         ProcessFileSpec = False
  278.     End If
  279. End Function
  280.