编写程序,建立一个打开文件对话框,然后通过这个对话框选择一个可执行文件,并执行它。例如,程序运行后,在对话框中选择Windows下的“计算器”程序,然后执行这个程序,打开“计算器”。

    解:在窗体上画一个命令按钮和一个通用对话框,然后编写如下代码。

Private Sub Command1_Click()
    CommonDialog1.FileName = ""
    CommonDialog1.Flags = vbofnfilemustexist
    CommonDialog1.Filter = "All Files|*.*|(*.exe)|*.exe"
    CommonDialog1.FilterIndex = 2
    CommonDialog1.DialogTitle = "Open File(*.EXE)"
    CommonDialog1.Action = 1
    If CommonDialog1.FileName = "" Then
        MsgBox "No file selectd", 37, "checking"
    Else
        x = Shell(CommonDialog1.FileName, vbNormalFocus)
    End If
 End Sub

程序运行后,单击命令按钮,将显示打开文件对话框,在该对话框中找到要执行的文件,例如 C:\Windows\System32\calc.exe  然后单击打开按钮,即可执行该文件。

来源:visual basic程序设计教程第四版答案(刘炳文)

本文链接:http://www.wb98.com/vb1/post/vb_12.4.html

本站文章搜索:

<< 上一篇下一篇 >>

搜索

Tags列表

扫我手机登录

赞助商链接