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

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