home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap16 / dlgrun1 / dlgrun.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-07-11  |  4.6 KB  |  147 lines

  1. VERSION 4.00
  2. Begin VB.Form dlgRun 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Run"
  5.    ClientHeight    =   1935
  6.    ClientLeft      =   1140
  7.    ClientTop       =   1515
  8.    ClientWidth     =   5145
  9.    Height          =   2340
  10.    Left            =   1080
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   1935
  15.    ScaleWidth      =   5145
  16.    ShowInTaskbar   =   0   'False
  17.    Top             =   1170
  18.    Width           =   5265
  19.    Begin VB.CommandButton cmdBrowse 
  20.       Caption         =   "&Browse..."
  21.       Height          =   375
  22.       Index           =   2
  23.       Left            =   3840
  24.       TabIndex        =   5
  25.       Top             =   1440
  26.       Width           =   1155
  27.    End
  28.    Begin VB.CommandButton cmdCancel 
  29.       Cancel          =   -1  'True
  30.       Caption         =   "Cancel"
  31.       Height          =   375
  32.       Index           =   1
  33.       Left            =   2640
  34.       TabIndex        =   4
  35.       Top             =   1440
  36.       Width           =   1155
  37.    End
  38.    Begin VB.CommandButton cmdOK 
  39.       Caption         =   "&OK"
  40.       Default         =   -1  'True
  41.       Height          =   375
  42.       Index           =   0
  43.       Left            =   1440
  44.       TabIndex        =   3
  45.       Top             =   1440
  46.       Width           =   1155
  47.    End
  48.    Begin VB.TextBox txtCommandLine 
  49.       Height          =   285
  50.       Left            =   840
  51.       TabIndex        =   2
  52.       Text            =   "Text1"
  53.       Top             =   840
  54.       Width           =   4095
  55.    End
  56.    Begin MSComDlg.CommonDialog Dialogs 
  57.       Left            =   300
  58.       Top             =   1380
  59.       _Version        =   65536
  60.       _ExtentX        =   847
  61.       _ExtentY        =   847
  62.       _StockProps     =   0
  63.    End
  64.    Begin VB.Label Label2 
  65.       AutoSize        =   -1  'True
  66.       Caption         =   "&Open:"
  67.       Height          =   195
  68.       Left            =   180
  69.       TabIndex        =   1
  70.       Top             =   900
  71.       Width           =   435
  72.    End
  73.    Begin VB.Label Label1 
  74.       Caption         =   "Type the Name of a program, folder, or document, and Windows with open it for you."
  75.       Height          =   435
  76.       Left            =   840
  77.       TabIndex        =   0
  78.       Top             =   180
  79.       Width           =   3855
  80.    End
  81.    Begin VB.Image Image1 
  82.       Height          =   480
  83.       Left            =   120
  84.       Picture         =   "dlgRun.frx":0000
  85.       Top             =   180
  86.       Width           =   480
  87.    End
  88. Attribute VB_Name = "dlgRun"
  89. Attribute VB_Creatable = False
  90. Attribute VB_Exposed = False
  91. Option Explicit
  92. Public CommandLine As String
  93. Private boolOK As Boolean
  94. Public Function Display() As Boolean
  95.     Me.Show vbModal
  96.     Display = boolOK
  97. End Function
  98. Public Function Execute() As Variant
  99.     Dim lngResult As Long
  100.     'This will return a variant of type error
  101.     'if the command line does not execute successfully
  102.     'Otherwise it returns the task ID as a variant
  103.     'to the calling procedure.
  104.     On Error Resume Next
  105.     lngResult = Shell(CommandLine, vbNormalFocus)
  106.     If Err.Number <> 0 Then
  107.         Execute = CVErr(Err.Number)
  108.     Else
  109.         Execute = lngResult
  110.     End If
  111. End Function
  112. Private Sub cmdBrowse_Click(Index As Integer)
  113.     Dialogs.Filter = "Executable Files|*.exe;*.com;*.bat;*.cmd;*.pif|All Files|*.*"
  114.     Dialogs.FilterIndex = 1
  115.     'These flags require the file to exist, use the Windows 95 interface
  116.     'and allow the use of long file names.
  117.     Dialogs.Flags = MSComDlg.FileOpenConstants.cdlOFNFileMustExist _
  118.         + MSComDlg.FileOpenConstants.cdlOFNExplorer _
  119.         + MSComDlg.FileOpenConstants.cdlOFNLongNames
  120.     'This allows the program to retrieve information when
  121.     'the user cancels the dialog.
  122.     Dialogs.CancelError = True
  123.     On Error Resume Next
  124.     'This uses the new method rather than the old Action property
  125.     Dialogs.ShowOpen
  126.     If Err.Number = 0 Then
  127.         txtCommandLine = Dialogs.FileName
  128.     Else
  129.         If Err.Number <> MSComDlg.ErrorConstants.cdlCancel Then
  130.             'If this were a "real" app
  131.             'more extensive error handling would
  132.             'be required
  133.             Err.Raise Number:=Err.Number
  134.         End If
  135.     End If
  136. End Sub
  137. Private Sub cmdCancel_Click(Index As Integer)
  138.     CommandLine = ""
  139.     boolOK = False
  140.     Me.Hide
  141. End Sub
  142. Private Sub cmdOK_Click(Index As Integer)
  143.     CommandLine = txtCommandLine
  144.     boolOK = True
  145.     Me.Hide
  146. End Sub
  147.