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