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

  1. VERSION 2.00
  2. Begin Form FileOpen 
  3.    BorderStyle     =   1  'Fixed Single
  4.    ClientHeight    =   3120
  5.    ClientLeft      =   1560
  6.    ClientTop       =   1770
  7.    ClientWidth     =   5580
  8.    Height          =   3525
  9.    Icon            =   FILEOPEN.FRX:0000
  10.    Left            =   1500
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   3120
  15.    ScaleWidth      =   5580
  16.    Top             =   1425
  17.    Width           =   5700
  18.    Begin DriveListBox DriveDropDown 
  19.       Height          =   315
  20.       Left            =   780
  21.       TabIndex        =   9
  22.       Top             =   2700
  23.       Width           =   3555
  24.    End
  25.    Begin PictureBox FileOpenIcon 
  26.       BorderStyle     =   0  'None
  27.       Height          =   495
  28.       Left            =   4725
  29.       Picture         =   FILEOPEN.FRX:0302
  30.       ScaleHeight     =   495
  31.       ScaleWidth      =   495
  32.       TabIndex        =   13
  33.       TabStop         =   0   'False
  34.       Top             =   2115
  35.       Width           =   495
  36.    End
  37.    Begin CommandButton NewButton 
  38.       Caption         =   "&None"
  39.       Height          =   480
  40.       Left            =   4440
  41.       TabIndex        =   12
  42.       Top             =   1305
  43.       Width           =   1080
  44.    End
  45.    Begin DirListBox DirListBox 
  46.       Height          =   1605
  47.       Left            =   2040
  48.       TabIndex        =   7
  49.       Top             =   1005
  50.       Width           =   2295
  51.    End
  52.    Begin FileListBox FileListBox 
  53.       Height          =   1785
  54.       Left            =   120
  55.       TabIndex        =   4
  56.       Top             =   825
  57.       Width           =   1815
  58.    End
  59.    Begin CommandButton CancelButton 
  60.       Cancel          =   -1  'True
  61.       Caption         =   "&Cancel"
  62.       Height          =   480
  63.       Left            =   4440
  64.       TabIndex        =   11
  65.       Top             =   720
  66.       Width           =   1080
  67.    End
  68.    Begin CommandButton OKButton 
  69.       Caption         =   "&OK"
  70.       Default         =   -1  'True
  71.       Height          =   480
  72.       Left            =   4440
  73.       TabIndex        =   10
  74.       Top             =   120
  75.       Width           =   1080
  76.    End
  77.    Begin TextBox FileSpecBox 
  78.       Height          =   300
  79.       Left            =   960
  80.       TabIndex        =   2
  81.       Text            =   "*.*"
  82.       Top             =   120
  83.       Width           =   3390
  84.    End
  85.    Begin Label DriveDropDownLabel 
  86.       Caption         =   "Dri&ves:"
  87.       Height          =   225
  88.       Left            =   120
  89.       TabIndex        =   8
  90.       Top             =   2745
  91.       Width           =   615
  92.    End
  93.    Begin Label AboutLabel 
  94.       Caption         =   "About"
  95.       Height          =   195
  96.       Left            =   4710
  97.       TabIndex        =   0
  98.       Top             =   2610
  99.       Width           =   555
  100.    End
  101.    Begin Label CurDirLabel 
  102.       Caption         =   "CurDirLabel"
  103.       Height          =   225
  104.       Left            =   2040
  105.       TabIndex        =   6
  106.       Top             =   750
  107.       Width           =   2295
  108.    End
  109.    Begin Label DirListLabel 
  110.       Caption         =   "&Directories:"
  111.       Height          =   225
  112.       Left            =   2040
  113.       TabIndex        =   5
  114.       Top             =   510
  115.       Width           =   975
  116.    End
  117.    Begin Label FileListLabel 
  118.       Caption         =   "Fi&les:"
  119.       Height          =   225
  120.       Left            =   120
  121.       TabIndex        =   3
  122.       Top             =   525
  123.       Width           =   495
  124.    End
  125.    Begin Label FileSpecLabel 
  126.       Alignment       =   1  'Right Justify
  127.       Caption         =   "&Filename:"
  128.       Height          =   225
  129.       Left            =   120
  130.       TabIndex        =   1
  131.       Top             =   150
  132.       Width           =   825
  133.    End
  134. Sub AboutLabel_Click ()
  135.     FileOpenIcon_Click
  136. End Sub
  137. Sub CancelButton_Click ()
  138.     Unload FileOpen
  139. End Sub
  140. Sub Command1_Click ()
  141.     FileOpen.Cursor = 11
  142. End Sub
  143. Sub DirListBox_Change ()
  144.     FileListBox.Path = DirListBox.Path
  145.     FileSpecBox.Text = FileListBox.Pattern
  146.     ChDir DirListBox.Path
  147.     CurDirLabel.Caption = LCase$(CurDir$)
  148. End Sub
  149. Sub DirListBox_Click ()
  150.     FileSpecBox.Text = DirListBox.List(DirListBox.ListIndex)
  151. End Sub
  152. Sub DriveDropDown_Change ()
  153.     On Error Resume Next
  154.     Err = False
  155. CheckDrive:
  156.     NewDrive = Left$(DriveDropDown.Drive, 2)
  157.     TestDrive$ = Dir$(NewDrive)
  158.     If Err Then
  159.         MsgBox "Drive not ready", 48, "FileOpen"
  160.         DriveDropDown.Drive = OldDrive
  161.         GoTo CheckDrive
  162.     Else
  163.         ChDrive DriveDropDown.Drive
  164.         OldDrive = NewDrive
  165.         DirListBox.Path = DriveDropDown.Drive
  166.     End If
  167.     On Error GoTo 0
  168. End Sub
  169. Sub FileListBox_Click ()
  170.     FileSpecBox.Text = FileListBox.FileName
  171.     PickFile = FileListBox.FileName
  172. End Sub
  173. Sub FileListBox_DblClick ()
  174.     OkButton_Click
  175. End Sub
  176. Sub FileOpenIcon_Click ()
  177.     MsgBox "Written by Eric Hall in MS VB 1.0" + CRLF + "Portions Copyright Microsoft", 64, "FileOpen"
  178. End Sub
  179. Sub FileSpecBox_Change ()
  180.     PickFile = ""
  181. End Sub
  182. Sub Form_Load ()
  183.     On Error Resume Next
  184.     CRLF = Chr$(10) + Chr$(13)
  185.     CommandLine$ = LTrim$(RTrim$(Command$))
  186.     If CommandLine$ = "" Then GoTo NoParms
  187.     Separator$ = ","
  188.     CLPS1% = InStr(1, CommandLine$, Separator$)
  189.     CLPS2% = InStr(CLPS1% + 1, CommandLine$, Separator$)
  190.     DialogTitle = LTrim$(RTrim$(Mid$(CommandLine$, 1, CLPS1% - 1)))
  191.     FileSpec = LCase$(LTrim$(RTrim$(Mid$(CommandLine$, CLPS1% + 1, CLPS2% - CLPS1% - 1))))
  192.     Executable = LTrim$(RTrim$(Mid$(CommandLine$, CLPS2% + 1)))
  193.         
  194.     If CLPS1% = 0 Then GoTo NoParms
  195.     If CLPS2% = 0 Then GoTo NoParms
  196.     If DialogTitle = "" Then DialogTitle = "FileOpen" Else DialogTitle = "FileOpen - " + DialogTitle
  197.     If FileSpec = "" Then FileSpec = "*.*"
  198.     If Executable = "" Then GoTo NoParms
  199.     If Err GoTo NoParms
  200.     GoTo LoadForm
  201. NoParms:
  202.     CmdLineErr$ = "TRUE"
  203.     Unload FileOpen
  204. LoadForm:
  205.     FileOpen.Caption = DialogTitle
  206.     FileListBox.Pattern = FileSpec
  207.     FileSpecBox.Text = FileListBox.Pattern
  208.     FileSpecBox.SelStart = 0
  209.     FileSpecBox.SelLength = Len(FileSpecBox.Text)
  210.     CurDirLabel.Caption = LCase$(CurDir$)
  211.     OldDrive = LCase$(Left$(DriveDropDown.Drive, 2))
  212.     On Error GoTo 0
  213. End Sub
  214. Sub Form_Unload (Cancel As Integer)
  215.     On Error Resume Next
  216.     If CmdLineErr = "TRUE" Then
  217.         MsgLine1$ = "There was a command line error!  The correct syntax is:" + CRLF
  218.         MsgLine2$ = CRLF
  219.         MsgLine3$ = "   1) Dialog title -- the default is FileOpen" + CRLF
  220.         MsgLine4$ = "   2) File specification -- the default is *.*" + CRLF
  221.         MsgLine5$ = "   3) Program to load -- You MUST specify this" + CRLF
  222.         MsgLine6$ = CRLF
  223.         MsgLine7$ = "Separate the 3 parameters with commas."
  224.         MsgBox MsgLine1$ + MsgLine2$ + MsgLine3$ + MsgLine4$ + MsgLine5$ + MsgLine6$ + MsgLine7$, 48, "FileOpen"
  225.     End If
  226. End Sub
  227. Sub NewButton_Click ()
  228.     On Error Resume Next
  229.     ChDrive Left$(DriveDropDown.Drive, 2)
  230.     ChDir DirListBox.Path
  231.     CommandLine = Executable
  232.     StartAppStatus = Shell(CommandLine, 3)
  233.         If Err Then
  234.             MsgBox "Error loading Application!" + CRLF + RTrim$(Error$(Err)) + "!", 48, "FileOpen"
  235.             CmdLineErr$ = "TRUE"
  236.             Unload FileOpen
  237.         Else
  238.             Unload FileOpen
  239.         End If
  240. EXITNEWBUTTON:
  241.     FileSpecBox.SetFocus
  242.     FileSpecBox.SelStart = 0
  243.     FileSpecBox.SelLength = Len(FileSpecBox.Text)
  244. End Sub
  245. Sub OkButton_Click ()
  246.     On Error Resume Next
  247.     Err = False
  248.     FileSpec = LCase$(LTrim$(RTrim$(FileSpecBox.Text)))
  249.     Screen.MousePointer = 11
  250. RunFileSpec:
  251.     Rem *** If user selects a file from FileListBox, load it and run.
  252.     If RTrim$(PickFile) <> "" Then
  253.         CommandLine = Executable + " " + PickFile
  254.         StartAppStatus = Shell(CommandLine, 3)
  255.         If Err Then
  256.             MsgBox "Error loading application!" + CRLF + RTrim$(Error$(Err)) + "!", 48, "FileOpen"
  257.             CmdLineErr = "TRUE"
  258.             Unload FileOpen
  259.         Else
  260.             CmdLineErr = "FALSE"
  261.             Unload FileOpen
  262.         End If
  263.     Rem *** If the user typed a full valid filename, go ahead and grab it
  264.     Else
  265.         TestFileSpec = Dir$(Left$(FileSpec, 2))
  266.         If Err Then
  267.             MsgBox "Drive not ready", 48, "FileOpen"
  268.             GoTo ExitOKButton
  269.         End If
  270.         PickFile = LCase$(Dir$(FileSpec))
  271.         If Len(PickFile) > 0 And PickFile = Right$(FileSpec, Len(PickFile)) Then
  272.             GoTo RunFileSpec
  273.         Else
  274.             If InStr(FileSpec, ".") = 0 Then
  275.                 FilePattern = Mid$(FileListBox.Pattern, InStr(FileListBox.Pattern, "."))
  276.                 TestFileSpec = LCase$(FileSpec + FilePattern)
  277.                 PickFile = LCase$(Dir$(FileSpec + FilePattern))
  278.                 If PickFile = "" Then GoTo PrepFileSpec
  279.                 If InStr(TestFileSpec, PickFile) > 0 Then
  280.                     FileSpec = FileSpec + FilePattern
  281.                     PickFile = FileSpec
  282.                     GoTo RunFileSpec
  283.                 End If
  284.             End If
  285.             PickFile = ""
  286.             Err = False
  287.             GoTo PrepFileSpec
  288.         End If
  289.     End If
  290. PrepFileSpec:
  291.     Rem *** Here we have to remove the trailing backslash if the user
  292.     Rem *** put it in.  Follows windows standard now...
  293.     If Right$(FileSpec, 1) = "\" Then
  294.         If Len(FileSpec) <> InStr(FileSpec, "\") Then
  295.             FileSpec = Left$(FileSpec, Len(FileSpec) - 1)
  296.         End If
  297.     End If
  298.     Rem *** Update the Filename property of the listbox so we can
  299.     Rem *** trigger the drive/path/pattern properties
  300.     FileListBox.FileName = FileSpec
  301.     If Err Then
  302.         Select Case Err
  303.             Case 380
  304.                 Rem *** Trap for empty floppy drive...
  305.                 MsgBox "Drive not ready", 48, "FileOpen"
  306.                 GoTo ExitOKButton
  307.             Case 76
  308.                 Rem *** Trap for invalid pathname...
  309.                 MsgBox "Directory does not exist", 48, "FileOpen"
  310.                 GoTo ExitOKButton
  311.             Case 53
  312.                 Rem *** Trap for attempt at filename...
  313.                 MsgBox "File does not exist", 48, "FileOpen"
  314.             Case Else
  315.                 Rem *** Trap for other errors...
  316.                 MsgBox "Error number " + Str$(Err) + CRLF + Error$(Err), 48, "FileOpen"
  317.         End Select
  318.     End If
  319.     NewDrive = Left$(FileListBox.Path, 2)
  320.     NewPath = FileListBox.Path
  321. ProcessFileSpec:
  322.     Rem *** Get the new drive, compare it to the old drive, and
  323.     Rem *** change drives, if necessary...
  324.     If UCase$(NewDrive) <> UCase$(OldDrive) Then
  325.         DriveDropDown.Drive = NewDrive
  326.         OldDrive = NewDrive
  327.         ChDrive NewDrive
  328.     End If
  329.     Rem *** Get the new path, and change to the new directory,
  330.     Rem *** if necessary...
  331.     If UCase$(NewPath) <> UCase$(CurDir$) Then
  332.         DirListBox.Path = NewPath
  333.         ChDir NewPath
  334.     End If
  335. ExitOKButton:
  336.     FileSpecBox.Text = FileListBox.Pattern
  337.     FileSpecBox.SetFocus
  338.     FileSpecBox.SelStart = 0
  339.     FileSpecBox.SelLength = Len(FileSpecBox.Text)
  340.     Screen.MousePointer = 0
  341.     On Error GoTo 0
  342. End Sub
  343.