Look at the case study Vfp:commondialog control

Source: Internet
Author: User
Tags filter define empty save file

VB can use the CommonDialog control to get "open", "Save as" and other standard dialog boxes, as well as file path and file name, in VFP can also use this control. The control is not visible at run time and is an ActiveX control. The commonly used events for this control are ShowOpen and Showsave, where ShowOpen is used to get the Open dialog box, Showsave to get the Save As dialog box, and the properties commonly used by the control are as follows:

FileName: Returns the file name of the selected file (including the file name of the path).

Filetitle: Returns the filename (plain file name without path).

Filter Property: Specifies the list item contents of the File Type list box in the Open or Save dialog box, as shown in the following figure:

This article is a small example of a CommonDialog control, run as shown below:

In the previous illustration, click the Select Table button to appear in the Open dialog box, you can select a table in the working directory to open and display the data in the table control, and click the Save File button to appear in the Save As dialog box, where you can save the current table file to a specific location.

The production steps are as follows:

A new form, set its AutoCenter property value to. T, and save it as "form 1.scx".

Add two command button command1~command2 to the form, and set their Caption property value to select table and save file in turn.

Third, add the CommonDialog control to the form:

Because the CommonDialog control is an ActiveX control, you need to register before you use it before you can see it and use it in the Form Control toolbar. The steps are as follows:

1, click the VFP system Menu "Tools" → "Options", in the Pop-up Options dialog box, select the Control tab, select the ActiveX control Radio box in this tab, in the list below, select Microsoft Common Dialog controls, Then click Set as Default, and then OK, as shown in the following figure:

2, click View Class on the Form Control toolbar, and in the Drop-down menu that appears, select ActiveX control, as shown in the following figure:

3, this control can be seen in the form Control toolbar, as shown in

You can then add a CommonDialog control to the form just as you would add other controls, and the Name property value for the control you just added defaults to "Olecontrol1", and for the convenience of writing the code, we modify its Name property value to "Commondialog1 ”。

Add a Table control grid1 below the form, and the property values are the default. Adjust the position of each control on the form appropriately, as shown in the following figure:

V. Add event code:

1, the form of the Init event code: THISFORM.GRID1.VISIBLE=.F.

2, the form of the Unload event code: use

3. Click event code for the "SELECT Table" command button (Command1):

Private MP,FN
mp= "" && log Open File path variable
thisform.commondialog1.filename= ""
thisform.commondialog1.filter= "Data table (DBF) |*.dbf" && define types
that Commondialong open Thisform.commondialog1.showopen && Open the Open dialog box
mp=thisform.commondialog1.filename && Get the path to the datasheet
fn=thisform.commondialog1.filetitle && Plain file names without paths
if empty (MP) =.f. && Determine if the path is null use
    & MP && Open this datasheet
    fn=left (Fn,len (FN)-4) && remove the last four bits of the path string ". dbf"
    THISFORM.GRID1.RECORDSOURCE=FN
    thisform.grid1.visible=.t.
    Thisform.refresh
endif

4, "Save File" command button (COMMAND2) Click event Code:

Private MyPath
mypath= "
thisform.commondialog1.filename=" "
thisform.commondialog1.filter=" data table ( DBF) |*.dbf && define Commondialong saved type
thisform.commondialog1.showsave && Open Save dialog
mypath= Thisform.commondialog1.fileName && Get the path where the datasheet is located
if empty (MyPath) =.f.
    Copy to Alltrim (MyPath)
    MessageBox ("File saved successfully!") ")
endif

Six, run "form 1.scx".

This example code is debugged in the win2003+vfp6.0 environment.

See the full set of "rookie also learn VFP" tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.