Learn Visual Foxpro

download Learn Visual Foxpro

of 138

description

Learn Visual Foxpro

Transcript of Learn Visual Foxpro

  • Visual Foxpro

    (Object-Oriented Programming OOP) (Structure Programming) Visual FoxPro OOP Visual FoxPro FoxBase, FoxPro Visual FoxPro

    Visual FoxPro 1. File New 2. Program 3. Program1

    Command Window MODIFY COMMAND Program1 Enter

    Visual FoxPro parameter -T VFP.EXE -T

    Visual FoxPro Program1 * Program1 #DEFINE myProgram "" PRIVATE nVAR myForm = CREATEOBJECT("TestForm") myForm.Show STORE 1 TO nVAR

  • 2

    DO WHILE nVAR

  • 3

    1. Program Do 2. Program1 DO Command Window DO Program1 Enter 1. File Open 2. file of type Program 3. OK Command Window MODIFY COMMAND Program1 Enter Visual FoxPro (Data and Field Types) (Storing Data) (Operators) (Building Expressions) (Data and Field Types) Visual FoxPro Data Type Description Size Range

    Character Any Text 1 Byte per Character Any Characters

    Currency Monetary amounts 8 Bytes -92222337203685477.5808 to 922337203685477.5807 Date Chronological data 8 Bytes 01/01/100 to 12/31/9999

  • 4

    Consisting of Month, Year and Date

    DateTime

    Chronological data Consisting of Month, Year ,Date and Time

    8 Bytes 01/01/100 to 12/31/9999, plus 00:00:00 a.m. to 11:59:59 p.m.

    Logical Boolean Value of true or false 1 Byte True(.T.) or False(.F.)

    Numeric Integers or Fractions 8 Bytes in Memory; 1-20 Bytes in table

    -9999999999E+19 to .9999999999E+20

    FoxPro .DBF Visual FoxPro DBF Table Visual FoxPro Field Type Description Size Range

    Double A double-precision Floating-point number 8 bytes +/-4.94065645841247E-324

    Float Same as Number 8 bytes in Memory:1-20 Bytes in table -.9999999999E+19 to .9999999999E+20

    General Reference to an OLE Object 4 bytes in table Limited by available memory

    Integer Interger values 4 bytes -2147483647 to 2147483647

    Memo Reference to a block of data 4 bytes in table Limited by available memory

  • 5

    TYPE() (Storing Data) (Container) Container Scope Example Constants Private #DEFINE myprogram "" Variables Public,Private STORE 1 to nVAR Arrays Public,Private cARRAY[1,1] = "" Fields Permanent storage REPLACE name WITH "" Object Properties Referenced through the object Testform.Caption = myProgram Visual FoxPro Contrainer ? ,, (Object Properties) (Constants) #DEFINE ConstantName eExpression #DEFINE myprogram "" #UNDEF ConstantName (Variables) STORE = STOR 1 TO nVAR nVAR = 1

  • 6

    (scope) (Private) (Public) PRIVATE MemVarList - - PRIVATE ALL [LIKE Skeleton | EXCEPT Skeleton] PUBLIC MemVarList - - PUBLIC [ARRAY] ArrayName1 (nRows1 [, nColumns1]) [, ArrayName2 (nRows2 [, nColumns2])] ... ? Public Visual FoxPro Private Private (procedure) Public (Arrays) memory DECLARE [cFunctionType] FunctionName IN LibraryName [AS AliasName] [cParamType1 [@] ParamName1, cParamType2 [@] ParamName2, ...] DIMENSION ArrayName1 (nRows1 [, nColumns1]) [, ArrayName2 (nRows2 [, nColumns2])] ... DIMENSION cARRAY[5] DECLARE cARRAY[2,5] (Fields) (record) Table Table Visual FoxPro CREATE TABLE | DBF TableName1 [NAME LongTableName] [FREE] (FieldName1 FieldType [(nFieldWidth [, nPrecision])] [NULL | NOT NULL]

  • 7

    [CHECK lExpression1 [ERROR cMessageText1]] [DEFAULT eExpression1] [PRIMARY KEY | UNIQUE] [REFERENCES TableName2 [TAG TagName1]] [NOCPTRANS] [, FieldName2 ...] [, PRIMARY KEY eExpression2 TAG TagName2 |, UNIQUE eExpression3 TAG TagName3] [, FOREIGN KEY eExpression4 TAG TagName4 [NODUP] REFERENCES TableName3 [TAG TagName5]] [, CHECK lExpression2 [ERROR cMessageText2]]) | FROM ARRAY ArrayName CREATE [FileName | ?] CREATE TABLE customer (SalesID c(6), CustName c(20),; FOREIGN KEY SalesId TAG SalesId REFERENCE SALESMAN) (Object) (class) 20 ( 5 ) Object-Oriented Programming hobby (properties) OOP (Operators) Visual FoxPro (Character Operators) (Date and Date Time Operators) (Logical Operators)

  • 8

    (Relational Operators) (Numeric Operators) (Character Operators) 2 + - 2 $ ? + () cVAR = ? cVAR () ?'' $ ' .T. () (Date and Date Time Operators) SET DATE DMY ? DATE() + 30 ( 15/09/98) 10/15/98 () ? DATE() - {17/06/98} 90 () (Logical Operators) () , NOT ! , AND , OR IF !(cVAR=) OR (nSaraly >= 50000) (Relational Operators) < > , # , != = == 2

  • 9

    (Numeric Operators) Operator Description ( ) 1 **, ^ 2 * , / , 3 % 4 + , - , 5 ? (4+5) * 10 - (12%10) ^ 2 86.00 () (Building Expressions) nVAR = 1 + 2 IF (nVAT = 10/100) FOR nVAR = 4 to 400 STEP 4 ? DATE() (Operators) (Constants) (Variable) (Function) Visual FoxPro 1. , _ (Under Score) 2. Under Score 3. 1 254 Field Free Table (file .DBF) Index Tag 10 4. Visual FoxPro

  • 10

    (Basic Programming) C , BASIC PASCAL 2 , (Decision) Visual FoxPro IF..ENDIF IF lExpression Commands [ELSE Commands] ENDIF IIF() IIF(lExpression, eExpression1, eExpression2) DO CASE ... ENDCASE DO CASE CASE lExpression1 Commands [CASE lExpression2 Commands ... CASE lExpressionN Commands] [OTHERWISE Commands] ENDCASE

  • 11

    Program2 * Program2 #DEFINE myProgram "" PRIVATE nVAR myForm = CREATEOBJECT("TestForm") myForm2 = CREATEOBJECT("DisplayColor") myForm.Show myForm2.Show myForm2.BackColor = RGB(255,0,0) READ EVENTS DEFINE CLASS TestForm AS FORM Caption = myProgram Top = 1 Left = 0 Height = 250 Width = 300 ADD OBJECT MyButton AS CommandButton WITH ; Top = 180, Left = 36, Height = 37, Width = 73, ; Caption = "Exit" ADD OBJECT MyGroup AS OptionGroup WITH ; AutoSize = .T. , ButtonCount = 5, BackStyle = 1, Value = 1 ,; Height=108,Left=36,Top=48,Width=78,; Option1.FontName = "CordiaUPC", Option1.FontSize = 16,; Option1.Caption = "",; Option1.Height = 18, Option1.Left = 5, ; Option1.Top = 5, Option1.Width = 68, ; Option2.FontName = "CordiaUPC", Option2.FontSize = 16, ; Option2.Caption = "", ;

  • 12

    Option2.Height = 18, Option2.Left = 5, ; Option2.Top = 25, Option2.Width = 68, ; Option3.FontName = "CordiaUPC", Option3.FontSize = 16, ; Option3.Caption = "", ; Option3.Height = 18, Option3.Left = 5, ; Option3.Top = 45, Option3.Width = 68, ; Option4.FontName = "CordiaUPC", Option4.FontSize = 16, ; Option4.Caption = "", ; Option4.Height = 18, Option4.Left = 5, ; Option4.Top = 65, Option4.Width = 68, ; Option5.FontName = "CordiaUPC", Option5.FontSize = 16, ; Option5.Caption = "", ; Option5.Height = 18, Option5.Left = 5, ; Option5.Top = 85, Option5.Width = 68 ADD OBJECT MyCheckBox AS CheckBox WITH ; Top = 84, Left = 144, Height = 49, Width = 121, ; FontName = "CordiaUPC", FontSize = 16, ; Caption = "", Value = 1 PROCEDURE myButton.Click RELEASE THISFORM CLEAR EVENTS ENDPROC PROCEDURE myCheckBox.Click IF myForm.myCheckBox.Value = 1 myForm2.Show ELSE myForm2.Hide ENDIF ENDPROC

  • 13

    PROCEDURE myGroup.Click DO CASE CASE myForm.myGroup.Value = 1 myForm2.BackColor = RGB(255,0,0) CASE myForm.myGroup.Value = 2 myForm2.BackColor = RGB(255,255,0) CASE myForm.myGroup.Value = 3 myForm2.BackColor = RGB(0,255,0) CASE myForm.myGroup.Value = 4 myForm2.BackColor = RGB(0,0,128) CASE myForm.myGroup.Value = 5 myForm2.BackColor = RGB(255,255,255) OTHERWISE myForm2.BackColor = RGB(255,255,255) ENDCASE myForm2.Refresh ENDPROC ENDDEFINE DEFINE CLASS DisplayColor AS FORM Caption = myProgram Top = 1 Left = 320 Height = 250 Width = 300 ENDDEFINE IF...ENDIF, IIF(), DO CASE...ENDCASE IF DO CASE ? DO CASE IF

  • 14

    ? (True) (False) (Loop) DO WHILE...ENDDO DO WHILE lExpression Commands [LOOP] [EXIT] ENDDO FOR...ENDFOR FOR MemVarName = nInitialValue TO nFinalValue [STEP nIncrement] Commands [EXIT] [LOOP] ENDFOR | NEXT SCAN...ENDSCAN SCAN [NOOPTIMIZE] [Scope] [FOR lExpression1] [WHILE lExpression2] [Commands] [LOOP] [EXIT] ENDSCAN Program3 * Program3 * Test will hold references to 5 forms PUBLIC ARRAY test(1) DIMENSION test(5) STORE 1 TO nCount

  • 15

    DO WHIL nCount

  • 16

    RELEASE ThisForm ENDPROC ENDDEFINE 3 DO WHILE DO WHILE foxbase FOR...NEXT SCAN FoxPro ( Visual FoxPro) DO WHILE FOR...NEXT SCAN FOR...NEXT SCAN 2 DO WHILE (command) (function) () MESSAGEBOX( ) (dialog box) MESSAGEBOX(cMessageText [, nDialogBoxType [, cTitleBarText] cMessageText nDialogBoxType Default 0 OK 1 OK Cancel 2 Abort, Retry, Ignore 3 Yes, No, Cancel 4 Yes No 5 Retry Cancel

  • 17

    16 Stop 32 Question mark 48 Exclamation point 64 Information (i) icon Default 0 256 512 Yes, No ,Cancel Stop Default 3 3 + 16 + 256 = 275 cMessageText 1 OK 2 Cancel 3 Abort 4 Retry 5 Ignore 6 Yes 7 No Command Windows nAnswer = MESSAGEBOX("Do you want to see the forms?" 36, "Multiple Instances - Arrays") ? nAnswer 6 ( Yes) (Classes) Visual FoxPro (Forms) , (Form Set) (Control) (Object) Object OOP Object (Properties) , (Events)

  • 18

    (Methods) Object ... Object Visual FoxPro (Base Class) Object (Sub Class) Sub Class Sub Class Object Sub Class ... , Sub Class Object (OOP) CheckBox EditBox ListBox Shape Column Form OLEBoundControl Spinner CommandButton FormSet OLEContainerControl TextBox CommandGroup Grid OptionButton Timer ComboBoxr Header OptionGroup ToolBar Container Image Page Control Label PageFrame Custom Line Separator

  • 19

    (Contrainers) -(Non-Contrainers) (Control Class) Form CommandButton Command button groups Command buttons

    Container Any controls Control Any controls Form Sets Forms, toolbars Forms Page frames, any controls, containers, custom

    Grid columns Column headers, any objects except forms, form sets, grid columns, and toolbars Grids Grid columns Option button groups Option buttons Page frames Pages Pages Any controls. containers, custom Toolbars Any controls, page fame, container . DEFINE CLASS ClassName1 AS ParentClass [[PROTECTED PropertyName1, PropertyName2 ...] PropertyName = eExpression ...] [ADD OBJECT [PROTECTED] ObjectName AS ClassName2 [NOINIT] [WITH cPropertylist]]...

  • 20

    [[PROTECTED] FUNCTION | PROCEDURE Name [NODEFAULT] cStatements [ENDFUNC | ENDPROC]]... ENDDEFINE DEFINE CLASS TestForm AS Form ADD OBJECT cmdExit As CommandButton WITH ; Caption = "E\

  • 21

    Object 2 1. (Absolute Referencing) 2. (Relative Reference) (Absolute Reference) Object myForm2.Show myForm2 Sub Class Form Show myForm2 _SCREEN.ActiveForm.BackColor = RGB(51*ncount,255,255) _SCREEN ActiveForm Form . BackColor myForm.txtDate.ForeColor = RGB(0,0,0) && black text myForm.txtDate.BackColor = RGB(192,192,192) && gray background myFormSet.myForm.Show myFormSet.myForm.cmdButton1.SetFocus (Relative Reference) keyword Parent The immediate container of the object. THIS The object. THISFORM The form that contains the object. THISFORMSET The form set that contains the object THIS.Caption = 'OK' && OK Object THIS.Parent.BackColor = RGB(192,0,0) && THISFORM.cmd1.Caption = 'OK' && OK object cmd1

  • 22

    Form THISFORMSET.myForm.cmd1.Caption = 'OK' Object Visual FoxPro object THIS.Paret.BackColor parent (Setting Properties) (Properties) Object Parent.Object.Property = Value myForm.txtDate.Value = DATE() && display the current date myForm.txtDate.Enabled = .T. && the Control is enabled myForm.txtDate.ForeColor = RGB(0,0,0) && black text myForm.txtDate.BackColor = RGB(192,192,192) && gray background Object code Visual FoxPro Object WITH...ENDWITH WITH ObjectName [.cStatements] ENDWITH WITH myForm.txtDate .Value = DATE() .Enabled = .T. .ForeColor = RGB(0,0,0) .BackColor = RGB(192,192,192) ENDWITH

  • 23

    (Calling Method) Object Object code Parent.Object.Method myForm.Show myForm.cmdExit.SetFocus Visual FoxPro parent :: (Scope Resolution Operator) cmdButton::Click() . (Data Base Design) Visual FoxPro (Bit) ( ASCII 8 1 ) 1 (Field) (Record) (File) (Database) ? 1. 2. 3. 4.

  • 24

    (Invoice) (Table) (Customer) CUST_ID

    NAME

    ADDRESS

    OUTSTNDING

    CREDITLMT

    TERM_DAY

    SALES_ID

    00001 . 198 . . 150000 20000 30 S0001

    00002 189 .

    0 50000 60 S0001

    00003 . 44 . . 9850 7500 15 S0002

    (Salesman) SALES_ID

    NAME

    ADDRESS

    COMMRATE

    S0001 393 . . 0.50% S0002 78 . . 0.75% (Invoice) INV_NO

    DATE

    CUST_ID

    9800001 15/09/1998 00002 9800002 01/10/1998 00001 9800003 01/10/1998 00002 (Invoice Detail)

  • 25

    INV_NO PROD_ID QUANTITY UNITPRICE 980001 AA001 5000 2.50 980001 BB001 850 10.00 980002 AA001 1000 2.25 98003 CC001 50 100.00 (Product) PROD_ID

    NAME

    ON_HAND

    UM

    UNITPRICE

    AA001 550000 2.50 BB001 4000 10.00 CC001 6 110.00 ? (relation) Visual FoxPro ? (Table) (Database) Command Window MODIFY COMMAND GenStru Enter

  • 26

    *GenStru.PRG * Create Database File CREATE DATABASE myDatabase * Create Database Table CREATE TABLE Salesman (Sales_ID c(5) PRIMARY KEY, ; Name c(60),Address c(120),CommRate n(5,2)) CREATE TABLE Customer (Cust_ID c(5) PRIMARY KEY,; Name c(60),Address c(120),Creditlmt n(3,0), ; Term_day n(3,0), Sales_ID c(5), ; FOREIGN KEY Sales_ID TAG Sales_ID REFERENCE Salesman) CREATE TABLE Product (Prod_ID c(5) PRIMARY KEY, ; Name c(60),On_Hand n(7,0),UM c(10),UnitPrice n(10,2)) CREATE TABLE Inv_Head (Inv_NO n(6,0) PRIMARY KEY, ; Date d(8),Cust_ID c(5), ; FOREIGN KEY Cust_ID TAG Cust_ID REFERENCE Customer) CREATE TABLE Inv_Dtl (Inv_NO n(6,0),Prod_ID c(5), ; Quantity n(6,0),UnitPrice n(10,2), ; FOREIGN KEY Inv_NO TAG Inv_NO REFERENCE Inv_Head ,; FOREIGN KEY Prod_ID TAG Prod_ID REFERENCE Product) *GenStru.PRG CREATE DATABASE 'MYDATABASE.DBC' ***** Table setup for SALESMAN ***** CREATE TABLE 'SALESMAN' (SALES_ID C(5) NOT NULL, ; NAME C(60) NOT NULL, ; ADDRESS C(120) NOT NULL, ; COMMRATE N(5, 2) NOT NULL) ***** Create each index for SALESMAN ***** ALTER TABLE 'SALESMAN' ADD PRIMARY KEY SALES_ID TAG SALES_ID ***** Change properties (if any) for SALESMAN ***** ***** Table setup for CUSTOMER ***** CREATE TABLE 'CUSTOMER' (CUST_ID C(5) NOT NULL, ;

  • 27

    NAME C(60) NOT NULL, ; ADDRESS C(120) NOT NULL, ; CREDITLMT N(3, 0) NOT NULL, ; TERM_DAY N(3, 0) NOT NULL, ; SALES_ID C(5) NOT NULL) ***** Create each index for CUSTOMER ***** ALTER TABLE 'CUSTOMER' ADD PRIMARY KEY CUST_ID TAG CUST_ID INDEX ON SALES_ID TAG SALES_ID ***** Change properties (if any) for CUSTOMER ***** ***** Table setup for PRODUCT ***** CREATE TABLE 'PRODUCT' (PROD_ID C(5) NOT NULL, ; NAME C(60) NOT NULL, ; ON_HAND N(7, 0) NOT NULL, ; UM C(10) NOT NULL, ; UNITPRICE N(10, 2) NOT NULL) ***** Create each index for PRODUCT ***** ALTER TABLE 'PRODUCT' ADD PRIMARY KEY PROD_ID TAG PROD_ID ***** Change properties (if any) for PRODUCT ***** ***** Table setup for INV_HEAD ***** CREATE TABLE 'INV_HEAD' (INV_NO N(6, 0) NOT NULL, ; DATE D NOT NULL, ; CUST_ID C(5) NOT NULL) ***** Create each index for INV_HEAD ***** ALTER TABLE 'INV_HEAD' ADD PRIMARY KEY INV_NO TAG INV_NO INDEX ON CUST_ID TAG CUST_ID ***** Change properties (if any) for INV_HEAD ***** ***** Table setup for INV_DTL ***** CREATE TABLE 'INV_DTL' (INV_NO N(6, 0) NOT NULL, ; PROD_ID C(5) NOT NULL, ; QUANTITY N(6, 0) NOT NULL, ; UNITPRICE N(10, 2) NOT NULL) ***** Create each index for INV_DTL *****

  • 28

    INDEX ON INV_NO TAG INV_NO INDEX ON PROD_ID TAG PROD_ID ***** Change properties (if any) for INV_DTL ***** *************** Begin Relations Setup ************** ALTER TABLE 'CUSTOMER' ADD FOREIGN KEY TAG SALES_ID REFERENCES SALESMAN TAG SALES_ID ALTER TABLE 'INV_HEAD' ADD FOREIGN KEY TAG CUST_ID REFERENCES CUSTOMER TAG CUST_ID ALTER TABLE 'INV_DTL' ADD FOREIGN KEY TAG INV_NO REFERENCES INV_HEAD TAG INV_NO ALTER TABLE 'INV_DTL' ADD FOREIGN KEY TAG PROD_ID REFERENCES PRODUCT TAG PROD_ID Save Ctrl+W DO GenStru Command Windows myDatabase CLOSE DATABASE MODIFY DATABASE myDatabase Database .PRG DO HOME()+'\TOOLS\GENDBC\GENDBC.PRG' Visual FoxPro (Compile .exe Copy GenStru Visual FoxPro 2 Free Table Database Table

  • 29

    .DBF ? Free Table .DBF Database Database Database Table .DBF Database Database File Database file Database Table Database Table Field 128 .DBF 8 Field 10 ( .DBC) CREATE DATABASE [DatabaseName | ?] CREATE DATABASE myDatabase Table ( .DBF) CREATE TABLE | DBF TableName1 [NAME LongTableName] [FREE] (FieldName1 FieldType [(nFieldWidth [, nPrecision])] [NULL | NOT NULL] [CHECK lExpression1 [ERROR cMessageText1]] [DEFAULT eExpression1] [PRIMARY KEY | UNIQUE] [REFERENCES TableName2 [TAG TagName1]] [NOCPTRANS] [, FieldName2 ...] [, PRIMARY KEY eExpression2 TAG TagName2 |, UNIQUE eExpression3 TAG TagName3] [, FOREIGN KEY eExpression4 TAG TagName4 [NODUP] REFERENCES TableName3 [TAG TagName5]] [, CHECK lExpression2 [ERROR cMessageText2]]) | FROM ARRAY ArrayName CREATE TABLE Customer (Cust_ID c(5) PRIMARY KEY,; Name c(60),Address c(120),Creditlmt n(3,0), ;

  • 30

    Term_day n(3,0), Sales_ID c(5), ; FOREIGN KEY Sales_ID TAG Sales_ID REFERENCE Salesman) database table ( database file table database table ) ** 128 Visual FoxPro 2 Structure Compound Compact Index (.CDX) Single-key (.IDX)

    Single-key Index Structural Compound Compact Index 1 1 1 100 240

    set index to file.idx table

    tag name .CDX ? INDEX ON eExpression TO IDXFileName | TAG TagName [OF CDXFileName] [FOR lExpression] [COMPACT] [ASCENDING | DESCENDING] [UNIQUE | CANDIDATE] [ADDITIVE] key word IDXFileName Single-key index Structural Compound Compact Index INDEX ON CUST_ID TAG CUST_ID INDEX ON SUBST(NAME,1,1) TAG NAME tag name ?tag(1) ?sys(14,1)

  • 31

    (1 index tag tag 2,3 .. ) compound index tag table tag SET ORDER TO [nIndexNumber | IDXIndexFileName | [TAG] TagName [OF CDXFileName] [IN nWorkArea | cTableAlias] [ASCENDING | DESCENDING]] SET ORDER TO 1 SET ORDER TO TAG NAME SET ORDER TO TAG SALES_ID USE USE SALESMAN ORDER 1 USE SALESMAN TAG SALES_ID program4.prg do program4 command window * program4.prg PUBLIC oform1 ON SHUTDOWN DO PRGERR && When program error click X (close foxpro) botton SET DELETE ON IF !USED('SALESMAN') select 0 use Salesman ENDIF SET ORDER TO TAG SALES_ID GO TOP SCATTER MEMVAR oform1=CREATEOBJECT("form1") oform1.Show()

  • 32

    oform1.cmdGroup.oTop.Enabled=.F. oform1.cmdGroup.oPrev.Enabled=.F. if reccount() = 0 oform1.cmdGroup.oNext.Enabled=.F. oform1.cmdGroup.oBott.Enabled=.F. endif READ EVENT RETURN DEFINE CLASS form1 AS form Height = 261 Width = 633 DoCreate = .T. AutoCenter = .T. Caption = "Salesman" ControlBox = .F. LockScreen = .F. Name = "Form1" ADD OBJECT osales_id AS textbox WITH ; ControlSource = "m.sales_id", ; Enabled = .F., ; Height = 24, ; Left = 132, ; Top = 24, ; Width = 73, ; Name = "oSales_id" ADD OBJECT oname AS textbox WITH ; ControlSource = "m.name", ; Enabled = .F., ; Height = 24, ;

  • 33

    Left = 132, ; Top = 60, ; Width = 265, ; Name = "oName" ADD OBJECT oaddress AS textbox WITH ; ControlSource = "m.address", ; Enabled = .F., ; Height = 24, ; Left = 132, ; Top = 96, ; Width = 456, ; Name = "oAddress" ADD OBJECT ocommrate AS textbox WITH ; Alignment = 3, ; Value = 0, ; ControlSource = "m.commrate", ; Enabled = .F., ; Format = "R", ; Height = 24, ; InputMask = "999.99", ; Left = 132, ; Top = 132, ; Width = 61, ; Name = "oCommrate" ADD OBJECT cmdgroup AS commandgroup WITH ; ButtonCount = 8, ; Value = 1, ; Height = 39, ; Left = 12, ;

  • 34

    Top = 192, ; Width = 615, ; Name = "cmdGroup", ; Command1.Top = 5, ; Command1.Left = 5, ; Command1.Height = 29, ; Command1.Width = 73, ; Command1.Caption = "Top", ; Command1.Name = "oTop", ; Command2.AutoSize = .F., ; Command2.Top = 5, ; Command2.Left = 81, ; Command2.Height = 29, ; Command2.Width = 73, ; Command2.Caption = "Previous", ; Command2.Name = "oPrev", ; Command3.Top = 5, ; Command3.Left = 157, ; Command3.Height = 29, ; Command3.Width = 73, ; Command3.Caption = "Next", ; Command3.Name = "oNext", ; Command4.Top = 5, ; Command4.Left = 233, ; Command4.Height = 29, ; Command4.Width = 73, ; Command4.Caption = "Bottom", ; Command4.Name = "oBott", ; Command5.AutoSize = .F., ; Command5.Top = 5, ; Command5.Left = 309, ; Command5.Height = 29, ;

  • 35

    Command5.Width = 73, ; Command5.Caption = "New", ; Command5.Name = "oNew", ; Command6.Top = 5, ; Command6.Left = 385, ; Command6.Height = 29, ; Command6.Width = 73, ; Command6.Caption = "Change", ; Command6.Name = "oChge", ; Command7.Top = 5, ; Command7.Left = 461, ; Command7.Height = 29, ; Command7.Width = 73, ; Command7.Caption = "Delete", ; Command7.Name = "oDele", ; Command8.Top = 5, ; Command8.Left = 537, ; Command8.Height = 29, ; Command8.Width = 73, ; Command8.Caption = "Exit", ; Command8.Name = "oExit" ADD OBJECT label1 AS label WITH ; Caption = "Salesman No.", ; Height = 18, ; Left = 24, ; Top = 24, ; Width = 88, ; Name = "Label1" ADD OBJECT label2 AS label WITH ; Caption = "Name", ;

  • 36

    Height = 18, ; Left = 75, ; Top = 60, ; Width = 37, ; Name = "Label2" ADD OBJECT label3 AS label WITH ; Caption = "Address", ; Height = 18, ; Left = 62, ; Top = 96, ; Width = 50, ; Name = "Label3" ADD OBJECT label4 AS label WITH ; Caption = "Commission", ; Height = 18, ; Left = 35, ; Top = 132, ; Width = 77, ; Name = "Label4" PROCEDURE cmdgroup.oTop.Click if !bof() go top scatt memvar this.enabled=.F. this.parent.oPrev.enabled=.F. this.parent.oNext.enabled=.T. this.parent.oBott.enabled=.T. endif thisform.refresh

  • 37

    ENDPROC PROCEDURE cmdgroup.oPrev.Click if !bof() skip -1 if bof() go top this.parent.oTop.enabled=.f. this.enabled=.f. endif scatt memvar this.parent.oNext.enabled=.T. this.parent.oBott.enabled=.T. endif thisform.refresh ENDPROC PROCEDURE cmdgroup.oNext.Click if !eof() skip if eof() go bott this.enabled=.F. this.parent.oBott.enabled=.F. endif scatt memvar this.parent.oTop.enabled=.T. this.parent.oPrev.enabled=.T. endif thisform.refresh ENDPROC

  • 38

    PROCEDURE cmdgroup.oBott.Click if !eof() go bott scatt memvar this.enabled=.F. this.parent.oNext.enabled=.F. this.parent.oTop.enabled=.T. this.parent.oPrev.enabled=.T. endif thisform.refresh ENDPROC PROCEDURE cmdgroup.oNew.Click if this.caption = 'New' scat memvar blank thisform.oSales_id.Enabled = .T. thisform.oName.Enabled = .T. thisform.oAddress.Enabled = .T. thisform.oCommrate.Enabled = .T. this.caption = 'Save' this.parent.oChge.caption = 'Cancel' this.parent.oTop.Enabled = .F. this.parent.oPrev.Enabled = .F. this.parent.oBott.Enabled = .F. this.parent.oNext.Enabled = .F. this.parent.oDele.Enabled = .F. this.parent.oExit.Enabled = .F. else do case case this.caption = 'Save' .and. this.parent.oChge.caption = 'Cancel' if !empty(thisform.oSales_id.value) INSERT INTO Salesman FROM MEMVAR

  • 39

    else wait window 'Sales_id must be Entry! Program not save' endif case this.caption = 'Save' .and. this.parent.oChge.caption = 'Reverse' GATHER MEMVAR endcase thisform.oSales_id.Enabled = .F. thisform.oName.Enabled = .F. thisform.oAddress.Enabled = .F. thisform.oCommrate.Enabled = .F. this.caption = 'New' this.parent.oChge.caption = 'Change' this.parent.oTop.Enabled = .T. this.parent.oPrev.Enabled = .T. this.parent.oBott.Enabled = .T. this.parent.oNext.Enabled = .T. this.parent.oDele.Enabled = .T. this.parent.oExit.Enabled = .T. endif thisform.refresh ENDPROC PROCEDURE cmdgroup.oChge.Click if recc() = 0 .and. this.parent.oChge.caption = 'Change' wait wind 'No data cannot change this record' else if this.caption = 'Change' thisform.oSales_id.Enabled = .T. thisform.oName.Enabled = .T. thisform.oAddress.Enabled = .T. thisform.oCommrate.Enabled = .T. this.caption = 'Reverse'

  • 40

    this.parent.oNew.caption = 'Save' this.parent.oTop.Enabled = .F. this.parent.oPrev.Enabled = .F. this.parent.oBott.Enabled = .F. this.parent.oNext.Enabled = .F. this.parent.oDele.Enabled = .F. this.parent.oExit.Enabled = .F. else do case case this.caption = 'Reverse' scatter memvar case this.caption = 'Cancel' && for addnew record go bott scatter memvar endcase thisform.oSales_id.Enabled = .F. thisform.oName.Enabled = .F. thisform.oAddress.Enabled = .F. thisform.oCommrate.Enabled = .F. this.caption = 'Change' this.parent.oNew.caption = 'New' this.parent.oTop.Enabled = .T. this.parent.oPrev.Enabled = .T. this.parent.oBott.Enabled = .T. this.parent.oNext.Enabled = .T. this.parent.oDele.Enabled = .T. this.parent.oExit.Enabled = .T. endif endif thisform.refresh ENDPROC

  • 41

    PROCEDURE cmdgroup.oDele.Click if recc() = 0 wait wind 'No data cannot delete this record' else nAnswer = MESSAGEBOX('Confirm Delete', 4 + 32 + 256,'Delete Record') DO CASE CASE nAnswer = 6 Delete go bott scatt memvar CASE nAnswer = 7 * not Delete ENDCASE endif Thisform.refresh ENDPROC PROCEDURE cmdgroup.oExit.Click USE SET DELETE OFF thisform.release CLEAR EVENT on shutdown ENDPROC ENDDEFINE PROCEDURE PRGERR CLEAR EVENT close all clear all on shutdown ENDPROC

  • 42

    Salesman 4-5 () program4 (table) USE USE [TableName | SQLViewName | ?] [IN nWorkArea | cTableAlias] [AGAIN] [NOREQUERY [nDataSessionNumber]] [NODATA] [INDEX IndexFileList | ? [ORDER [nIndexNumber | IDXFileName | [TAG] TagName [OF CDXFileName] [ASCENDING | DESCENDING]]]] [ALIAS cTableAlias] [EXCLUSIVE] [SHARED] [NOUPDATE] table table table (Work Area) table SELECT nWorkArea | cTableAlias command windows ( database MYDATABASE ) CLOSE ALL OPEN DATABASE MYDATABASE SELECT 1 USE SALESMAN

  • 43

    BROWSE SELECT 2 USE CUSTOMER BROWSE SELECT SALESMAN BROWSE SELECT 0 USE PRODUCT BROWSE table SALESMAN . 1 table CUSTOMER . 2 table PRODUCT 3 SELECT 0 3 table () Visual FoxPro INSERT INTO Salesman (SALES_ID,NAME,ADDRESS,COMMRATE), ; VALUE("10099","MR.SOMCHAI","175 SATHORN RD.",0.50) BROWSE SELECT Salesman < APPEND BLANK REPLACE SALES_ID WITH "10099", NAME WITH "MR.SOMCHAI", ; ADDRESS WITH "175 SATHORN RD.", COMMRATE WITH 0.50 BROWSE table SALESMAN . INSERT INTO INSERT INTO dbf_name [(fname1 [, fname2, ...])] VALUES (eExpression1 [, eExpression2, ...]) - Or - INSERT INTO dbf_name FROM ARRAY ArrayName | FROM MEMVAR

  • 44

    MEMVAR ? Visual FoxPro (memory variables) (field) table table m. m.sales_id , m.name MEMVAR ... MEMVAR table table table update table program4 scatter memvar, gather memvar table command windows CLOSE ALL OPEN DATABASE MYDATABASE USE SALESMAN IN 1 BROWSE && Esc browse GO TOP SCATTER MEMVAR ? m.sales_id + m.name + m.address + TRANSFORM(m.commrate, '@z 999.99') m.name = 'MR.ARKIRA SUPERMAN' m.commrate = 7.80 GATHER MEMVAR BROWSE m.name='MRS.SOMSRI' REPLACE NAME WITH m.name BROWSE SCATTER table GATHER update table . REPLACE GATHER update gatter 3 SCATTER [FIELDS FieldNameList

  • 45

    | FIELDS LIKE Skeleton | FIELDS EXCEPT Skeleton] [MEMO] TO ArrayName | TO ArrayName BLANK | MEMVAR | MEMVAR BLANK | NAME ObjectName MEMVAR BLANK SCATTER MEMVAR BLANK GATHER FROM ArrayName | MEMVAR | NAME ObjectName [FIELDS FieldList | FIELDS LIKE Skeleton | FIELDS EXCEPT Skeleton] [MEMO] REPLACE FieldName1 WITH eExpression1 [ADDITIVE] [, FieldName2 WITH eExpression2 [ADDITIVE]] ... [Scope] [FOR lExpression1] [WHILE lExpression2] [IN nWorkArea | cTableAlias] [NOOPTIMIZE] DELETE [Scope] [FOR lExpression1] [WHILE lExpression2] [IN nWorkArea | cTableAlias] [NOOPTIMIZE] DELETE FROM [DatabaseName!]TableName [WHERE FilterCondition1 [AND | OR FilterCondition2 ...]] table dBASE table RECALL [Scope] [FOR lExpression1] [WHILE lExpression2] [NOOPTIMIZE] PACK table

  • 46

    (structure) ZAP FoxPro (Function) ? ? Visual FoxPro 2 1. (Visual FoxPro function) 2. (user-defined function (UDF)) 1. FUNCTION 2. 254 Visual FoxPro 10 3. Visual FoxPro 4. (parameter) 5. 1 24 6. (NULL) 7. .... 1. Visual FoxPro 2. 32 ( 32 )

  • 47

    ( Visual FoxPro ) myVAR = DATE() STOR MONTH(DATE()) TO thisMonth =CAPSLOCK(.T.) && DO WHILE !EOF() INSERT INTO Salesman(LASTUPDATE) VALUE(DATE()) () Salesman INSERT INTO Visual FoxPro UTILITY.PRG command windows modify command UTILITY FUNCTION MyMessage PARAMETER cMessageText,cMessageTitle * 4 = Yes and No buttons * 32 = Question mark icon * 256 = Secound buttons is default * return value 6 for click YES * return value 7 for click NO RETURN MESSAGEBOX(cMessageText,4+32+256,cMessageTitle) SET PROCEDURE TO UTILITY UTILITY command windows ? MyMessage('','') nAnswer = MyMessage('','') ?nAnswer Visual FoxPro

  • 48

    Visual FoxPro (Procedure) set procedure to .... .prg MyMessage MyMessage.prg Error File '????????.prg' does not exist Library ? utility.prg 1 memory * utility.prg FUNCTION MyMessage ...... RETURN FUNCTION tCDOW PARAMETER dDATE nDay=DOW(dDATE) DO CASE CASE nDAY=1 RETRUN '' CASE nDAY=2 RETRUN '' CASE nDAY=3 RETRUN '' CASE nDAY=4 RETRUN '' CASE nDAY=5 RETRUN '' CASE nDAY=6 RETRUN '' CASE nDAY=7

  • 49

    RETRUN '' ENDCASE RETURN '' FUNCTION myFunction ...... RETURN ..... Visual FoxPro set procedure to SET PROCEDURE TO [FileName1 [, FileName2, ...]] [ADDITIVE] SET PROCEDURE TO UTILITY,MYFUNCTION,STATFUNCTION SET PROCEDURE TO FORMFUNCTION ADDITIVE main program Download NUM2CH.PRG * ---FUNCTION NUM2CH * ---...... (9,999,999,999.99) * ---........ Kasem K. * ---....... 12.08.92 *-- ...... cSTRING=NUM2CH(9999.22) *************************************************************** FUNCTION NUM2CH PARA mNUM && 10.2 PUBL mTCH(9),mTDEC(10) mTCH(1)='' mTCH(2)='' mTCH(3)='' mTCH(4)='' mTCH(5)='' mTCH(6)=''

  • 50

    mTCH(7)='' mTCH(8)='' mTCH(9)='' mTDEC(1) ='' mTDEC(2) ='' mTDEC(3) ='' mTDEC(4) ='' mTDEC(5) ='' mTDEC(6) ='' mTDEC(7) ='' mTDEC(8) ='' mTDEC(9) ='' mTDEC(10)='' mSTNUM=STR(mNUM*100,12) mSTTHAI='' mCNT=1 DO WHIL mCNT

  • 51

    ENDIF ENDIF ELSE IF mCHNUM='2'.AND.(mCNT=3.OR.mCNT=9) mSTTHAI=mSTTHAI+'' ELSE mSTTHAI=mSTTHAI+mTCH(VAL(mCHNUM)) ENDIF ENDIF mSTTHAI=mSTTHAI+mTDEC(mCNT) ENDIF ENDIF mCNT=mCNT+1 ENDDO mSTTHAI=mSTTHAI+'' IF SUBSTR(mSTNUM,11,2)='00' mSTTHAI=mSTTHAI+'' ELSE mCHNUM=SUBSTR(mSTNUM,11,1) IF mCHNUM#'0' IF mCHNUM#'1' IF mCHNUM='2' mSTTHAI=mSTTHAI+'' ELSE mSTTHAI=mSTTHAI+mTCH(VAL(mCHNUM)) ENDIF ENDIF mSTTHAI=mSTTHAI+mTDEC(9) ENDIF mCHNUM=SUBSTR(mSTNUM,12,1) IF mCHNUM#'0' IF mCHNUM='1'.AND.SUBSTR(mSTNUM,11,1)#'0'

  • 52

    mSTTHAI=mSTTHAI+'' ELSE mSTTHAI=mSTTHAI+mTCH(VAL(mCHNUM)) ENDIF ENDIF mSTTHAI=mSTTHAI+'' ENDIF RETU mSTTHAI * ---TSCDOW.PRG * ---........ Kasem K. * ---....... 12.08.92 *-- ...... cDayofWeek=TSCDOW(DATE()) * ---.... ROUTINE FUNCTION TSCDOW PARA mdtm mdtnm=DOW(mdtm) mcdm=SUBST('.....',2*mdtnm-1,2) RETU (mcdm) *---------------------------------------- * : MLOGIC.PRG * : * : 01/09/92 * : GAME 2022 * : C= , P = *---------------------------------------- PROCEDURE MLOGIC DECL S(5),X(5) DEFI WIND MLOGIC FROM 1,10 TO 21,45; TITLE "MASTER LOGIC" FOOT "ESC - EXIT"; GROW SYSTEM ZOOM COLO N/BG,N/BR,B+/W ACTI WIND MLOGIC DO WHIL .T.

  • 53

    CLEA STOR .F. TO FLAG STOR 0 TO S(1),S(2),S(3),S(4),S(5) STOR 0 TO L,POSI,COLF STOR 0 TO SCORE STOR '' TO Q_A @0,1 SAY 'SELECT : ' COLO 5+/3 @2,0 SAY 'C P' COLO 2+/3 @2,4 TO 2,22 @0,24 TO 9,32 @1,25 SAY 'LEGENT' COLO 6+/3 @2,25 SAY '1' @2,28 SAY ' ' COLO /1 @3,25 SAY '2' @3,28 SAY ' ' COLO /2 @4,25 SAY '3' @4,28 SAY ' ' COLO /3 @5,25 SAY '4' @5,28 SAY ' ' COLO /4 @6,25 SAY '5' @6,28 SAY ' ' COLO /5 @7,25 SAY '6' @7,28 SAY ' ' COLO /6 @8,25 SAY '7' @8,28 SAY ' ' COLO /7 @10,24 TO 13,32 @11,25 SAY 'SCORE' DO WHIL SCORE < 15 IF SCORE=0 FOR I = 1 TO 5 STOR STR(INT(RAN(1,8)),1) TO X(I) Q_A=Q_A+X(I)

  • 54

    NEXT @ 3,0 SAY '=>' COLO 0/3 ELSE @ 3+SCORE-1,1 SAY ' ' @ 3+SCORE,0 SAY '=>' COLO 0/3 ENDIF @1, 6 GET S(1) PICT'@Z 9' RANG 1,7 COLO ,7+; VALID(SAYCOL(S(1),1,6) .AND.SAYCOL(S(1),3+L,6 )) @1,10 GET S(2) PICT'@Z 9' RANG 1,7 COLO ,7+; VALID(SAYCOL(S(2),1,10).AND.SAYCOL(S(2),3+L,10)) @1,14 GET S(3) PICT'@Z 9' RANG 1,7 COLO ,7+; VALID(SAYCOL(S(3),1,14).AND.SAYCOL(S(3),3+L,14)) @1,18 GET S(4) PICT'@Z 9' RANG 1,7 COLO ,7+; VALID(SAYCOL(S(4),1,18).AND.SAYCOL(S(4),3+L,18)) @1,22 GET S(5) PICT'@Z 9' RANG 1,7 COLO ,7+; VALID(SAYCOL(S(5),1,22).AND.SAYCOL(S(5),3+L,22)) READ mKEY=READK() DO CASE CASE mKEY=12.OR.mKEY=268 FLAG=.T. EXIT ENDCASE * PROCESS STOR 0 TO POSI,COLF FOR I = 1 TO 5 IF STR(S(I),1)=X(I) POSI=POSI+1 ENDIF IF STR(S(I),1)$Q_A COLF=COLF+1 ENDIF

  • 55

    NEXT IF POSI=5 SCORE=SCORE+1 @ 12,27 SAY SCORE PICT '@Z 99' TEMP=WARNN(' YOU HAVE A WINNER ! ',10) EXIT ENDIF * END PROCESS SCORE = SCORE+1 @ 3+L,0 SAY COLF PICT '9' &&COLO 7+/3 @ 3+L,2 SAY POSI PICT '9' &&COLO 7+/3 @ 12,27 SAY SCORE PICT '@Z 99' L = L +1 ENDDO IF FLAG EXIT ENDIF IF POSI#5 DEFI WIND IWIN FROM 7,1 TO 12,29; TITLE "o REPLY BOX o" GROW SYSTEM ZOOM COLO N/N,N/BR,B+/W ACTI WIND IWIN @0,1 TO 4,25 @1, 4 SAY ' '+X(1)+' ' COLO 7+/&X(1) @1, 8 SAY ' '+X(2)+' ' COLO 7+/&X(2) @1,12 SAY ' '+X(3)+' ' COLO 7+/&X(3) @1,16 SAY ' '+X(4)+' ' COLO 7+/&X(4) @1,20 SAY ' '+X(5)+' ' COLO 7+/&X(5) @2, 4 SAY ' ' COLO /&X(1) @2, 8 SAY ' ' COLO /&X(2) @2,12 SAY ' ' COLO /&X(3) @2,16 SAY ' ' COLO /&X(4) @2,20 SAY ' ' COLO /&X(5)

  • 56

    TEMP=WARNN(' I WINNER !!! ',10) RELE WIND IWIN ENDIF ENDDO RELE WIND MLOGIC RETU FUNCTION SAYCOL PARA SEL,ROW,COLX CSEL=STR(SEL,1) @ROW,COLX-2 SAY ' '+CSEL COLO &CSEL+/&CSEL,/&CSEL RETU .T. * ---RAN.PRG * ---...... Kasem K. * ---... 17/09/92 * ---.... FUNCTION RAN PARA RA,RB RETU (RB-RA)*RAND()+RA *!********************************************************************* *! *! Procedure: WARNN *! *!********************************************************************* PROCEDURE warnn PARA mmsg,mtime *SET COLO OF SCHE 9 TO N/BG,N/RB,RG/W mlen=lcut(mmsg)

    mmsg=' '+REPL(' ',LEN(mmsg)- mlen)+mmsg+' ' DEFI WIND warnn FROM 19,4 TO 21,LEN(mmsg)+5 SYST ;

  • 57

    SHAD FLOAT NOZOOM COLO SCHE 9 ACTI WIND warnn *@23,40-(mLEN/2) SAY mMSG @0,0 SAY mmsg ??CHR(7) i=INKEY(mtime) *@23,40-(mLEN/2) SAY SPAC(LEN(mMSG)) RELE WIND warnn RETU && Download ITHAI.PRG * ---ITHAI.PRG * ---... 06/02/35 * ---.... ROUTINE FUNCTION INDEX THAI LANGUAGE * index on ithai(name) tag sortthai && * filed 1 sortname * REPLACE SORTNAME WITH ITHAI(NAME) SQL FUNCTION ithai PARA str0 mstr=TRIM(str0)+' ' mlen=LEN(mstr) IF mlen

  • 58

    mcnt=mcnt+1 ENDIF mcnt=mcnt+1 ENDDO mcnt=1 DO WHIL mcnt

  • 59

    cnt0 = cnt0 + 1 ENDDO RETU (LEN(mstr) - cnt00) *!********************************************************************* *! *! Procedure: STIFF *! *!********************************************************************* FUNCTION stiff PARA ma,mb mb=TRIM(LTRIM(mb)) mt=LEFT(ma,LEN(ma)-LEN(mb))+mb RETU mt Visual Class Library Visual Class Library(.VCX) ? Visual FoxPro base class (font) Textbox,Label,CommandButton properties ,event ,method Visual FoxPro CREATE CLASS CREATE CLASS ClassName | ? [OF ClassLibraryName1 | ?] [AS cBaseClassName [FROM ClassLibraryName2]] [NOWAIT] command window CREATE CLASS MyTextBox

  • 60

    Class Name MyTextBox Based On sub-class TextBox Store In .VCX MyClass OK CREATE CLASS MyTextBox OF MyClass AS TextBox MyTextBox

    Properties ( mouse properties) FontName CordiaUPC FontSize 14 FontBold .F. Ctrl+W (sub-class) control base class base class Visual FoxPro SET CLASSLIB TO ClassLibraryName [ADDITIVE] [ALIAS AliasName]

  • 61

    SET CLASSLIB TO MyClass ADDITIVE form designer form controls Add .VCX (sub-class) properties,event,method Code program Visual Class Libary(VCX) command window DO (_BROWSER) && Tools Class Browser MyClass.VCX VCX

    CREATE CLASS

    Double Click soruce code class browser source code

  • 62

    class browser file of type form Visual Class Library DO (_BROWSE) command window clock Class Name digitalclock Based On Container OK Class Designer Form Designer Label Form Control Timer Properties digitalclock properties Width = 145 Height = 30 BorderWidth = 0 Name = "digitalclock" label properties AutoSize = .F. FontSize = 15 Alignment = 2 Caption = "" Height = 27 Left = 0 Top = 0 Width = 145 Name = "Label1" init event this.caption=time() timer properties Interval = 1000 Name = "Timer1" timer event this.parent.label1.caption = time()

  • 63

    MODIFY COMMAND PROGRAM5 command window do program5 .... * PROGRAM5.PRG PUBLIC oform1 SET CLASSLIB TO HOME() + 'clock.vcx' ADDITIVE oform1=CREATEOBJECT("form1") oform1.Show() RETURN ************************************************** DEFINE CLASS form1 AS form Top = 0 Left = 0 Height = 81 Width = 193 DoCreate = .T. Caption = "" Name = "Form1" ADD OBJECT digitalclock1 AS digitalclock WITH ; Top = 24, Left = 24, Width = 145, Height = 30, ; Name = "Digitalclock1", ; Label1.Name = "Label1", ; Timer1.Name = "Timer1" ENDDEFINE *-- EndDefine: form1 ************************************************** properties Object.Name[ = cName] Timer1.Name="Timer1" object

  • 64

    object Timer.Interval[ = nTime] INTERVAL = 1000 (loop) 1000 1 timer event timer event label1

    .VCX (Visual Class Library) .VCX USE PACK USE .VCX Visual Class Library DOWNLOAD properties event(method) command window do (_browser) CALCULATOR .VCX Class Name = calac Based On = commandbutton

  • 65

    OK properties Height = 27 , Width = 30 , Caption = "AC" , Name = "calac" Event Click WITH This.parent .r_LCalculate = .F. .r_LNewValue = .T. .r_LNewMath = .T. .calText.Value = "" .calmath.Value = "" .r_NCaltxt = 0 .r_ColdMath = "+" .r_LDot = .T. ENDWITH Event Keypress with this.parent =.m_keypress(nKeyCode) endwith Class Name = calmath Based On = textbox properties Alignment = 2 , Enabled = .F. , Height = 24 , Width = 20 , Name = "calmath" Class Name = caltext Based On = textbox properties Alignment = 1 , Enabled = .F. , Height = 24 , Width = 192 , Name = "caltext" , ControlSource = "" Class Name = calnumber Based On = commandbutton

  • 66

    properties Height = 27 , Width = 30 , Caption = "" , Name = "calnumber" Event Click WITH This.parent IF this.caption="." .and. !.r_ldot RETURN ENDIF IF this.caption="." .r_ldot = .f. ENDIF IF .r_LNewValue .calText.value = This.Caption ELSE .calText.value = ALLTRIM(.calText.value) + This.Caption ENDIF .r_LNewValue = .F. .r_LCalculate = .T. .r_LNewMath = .T. ENDWITH Event Keypress with this.parent =.m_keypress(nKeyCode) endwith Class Name = calsign && event keypress calnumber Based On = calnumber && properties calnumber properties Name = "calsign" Event Click with this.parent

  • 67

    if .r_lnewmath .cmdenter.click .r_coldmath = this.caption .calmath.value = this.caption .r_lnewvalue = .t. .r_ldot = .t. endif endwith properties event(method) Visual FoxPro properties event(method) event(method) Class Name = calculator Based On = container properties Height = 220 , Width = 160 , BorderWith = 0 , Name = "calculator" properties Class New Property property property 6 r_LCalculate r_LNewValue r_LNewMath r_NCalTxt r_COldMath r_LDot properties calculator properties Other properties r_LCalculate = .F. r_LNewValue = .T.

  • 68

    r_LNewMath = .T. r_NCalTxt = 0 r_COldMath = "+" r_LDot = .T. method Class New Method Method 2 method m_str && 123 "123" m_keypress && container event method m_str properties metohd methods method m_str LPARAMETERS pnValue LOCAL lcValue lcValue = ALLTRIM(STR(pnValue, 20, 8)) * Now remove all zeros after the decimal point DO WHILE RIGHT(lcValue, 1) = '0' lcValue = LEFT(lcValue, LEN(lcValue)-1) ENDDO * Remove the decimal point if it is the last character IF RIGHT(lcValue, 1) = '.' lcValue = LEFT(lcValue, LEN(lcValue)-1) ENDIF RETURN (lcValue) method m_keypress LPARAMETERS nKeyCode LOCAL c_Chr,c_Click,c_Setfocus do case case nKeyCode = 27 && Esc = close calculator thisform.release() case nKeyCode = 13 && Enter this.cmdenter.click

  • 69

    this.cmdenter.setfocus case BETWEEN(chr(nKeyCode),"0","9") c_chr=chr(nKeyCode) c_Click="this.cmd"+c_chr+".click" c_Setfocus="this.cmd"+c_chr+".setfocus" &c_click &c_Setfocus case chr(nKeyCode) = "." this.cmddecimal.click this.cmddecimal.setfocus case INLIST(chr(nKeyCode),"C","c") this.calac10.click this.calac10.setfocus case chr(nKeyCode) = "+" this.calplus.click this.calplus.setfocus case chr(nKeyCode) = "-" this.calminus.click this.calminus.setfocus case chr(nKeyCode) = "*" this.calmult.click this.calmult.setfocus case chr(nKeyCode) = "/" this.caldiv.click this.caldiv.setfocus endcase properties methods container calculator Visual Class Library(.VCX) form control container calculator

  • 70

    form controls Add CALCULATOR.VCX Enter calsign form control container calculator commandbutton 1 properties Top = 192 , Left = 37 , Height = 24 , Width = 84 Caption = "Enter" , TabIndex = 1 , Name = "CmdEnter" Click Event WITH This.parent if .r_lcalculate if !empty(.r_ColdMath) do case case .r_ColdMath = "+" .r_Ncaltxt = .r_Ncaltxt + VAL(.calText.Value) case .r_ColdMath = "-" .r_Ncaltxt = .r_Ncaltxt - VAL(.calText.Value) case .r_ColdMath = "*" .r_Ncaltxt = .r_Ncaltxt * VAL(.calText.Value) case .r_ColdMath = "/" .r_Ncaltxt = .r_Ncaltxt / VAL(.calText.Value) endcase endif .r_LNewValue = .T. .r_LDot = .T. .calText.value = .m_str(.r_NcalTxt) .r_lcalculate = .F. endif ENDWITH enter 0 9 1 calnumber form control container calculator

  • 71

    properties Top = 120 , Left = 11 , Caption = "1" , TabIndex = 2 , Name = "cmd1" 2 calnumber form control container calculator properties Top = 120 , Left = 47 , Caption = "2" , TabIndex = 3 , Name = "cmd2" 3 calnumber form control container calculator properties Top = 120 , Left = 83 , Caption = "3" , TabIndex = 4 , Name = "cmd3" 4 calnumber form control container calculator properties Top = 84 , Left = 11 , Caption = "4" , TabIndex = 5 , Name = "cmd4" 5 calnumber form control container calculator properties Top = 84 , Left = 47 , Caption = "5" , TabIndex = 6 , Name = "cmd5" 6 calnumber form control container calculator properties Top = 84 , Left = 83 , Caption = "6" , TabIndex = 7 , Name = "cmd6" 7 calnumber form control container calculator properties Top = 48 , Left = 11 , Caption = "7" , TabIndex = 8 , Name = "cmd7" 8 calnumber form control container calculator properties Top = 48 , Left = 47 , Caption = "8" , TabIndex = 9 , Name = "cmd8" 9 calnumber form control container calculator

  • 72

    properties Top = 48 , Left = 83 , Caption = "9" , TabIndex = 10 , Name = "cmd9" 0 calnumber form control container calculator properties Top = 155 , Left = 11 , Caption = "0" , TabIndex = 11 , Name = "cmd0" . () calnumber form control container calculator properties Top = 155 , Left = 47 , Caption = "." , TabIndex = 12 , Name = "cmddecimal" + () calsign form control container calculator properties Top = 155 , Left = 83 , Caption = "+" , TabIndex = 13 , Name = "calplus" - () calsign form control container calculator properties Top = 155 , Left = 119 , Caption = "-" , TabIndex = 14 , Name = "calminus" * () calsign form control container calculator properties Top = 120 , Left = 119 , Caption = "*" , TabIndex = 15 , Name = "calmult" / () calsign form control container calculator properties Top = 84 , Left = 119 , Caption = "/" , TabIndex = 16 , Name = "caldiv" AC calac form control container calculator properties Top = 48 , Left = 119 , Caption = "AC" , TabIndex = 17 , Name = "calac10" caltext form control

  • 73

    container calculator properties Top = 12 , Left = 12 , Height = 24 , Width = 119 , TabIndex = 0 , Name = "caltext" caltext form control container calculator properties Top = 12 , Left = 130 , TabIndex = 0 , Name = "calmath" Visual Class Library Calculator create form calcform command window Enter form designer form control Add CALCULATOR.VCX Visual Class calculator container save do form calcform command window (Toolbar) DOWNLOAD Visual Class toolbar Visual Class Library toolbar DO (_BROWSE) command window MyToolbar Class Name toolbar1 Based On Toolbar OK Class Designer Form Designer properties toolbar1 properties Caption ( Spacebar ) ControlBox = .F.

  • 74

    Init Event This.Dock(0) dock toolbar . Main Visual FoxPro Window ToolBar.Dock [nLocation [, X, Y]] nLoction toolbar nLocation -1 0 Main Visual FoxPro Window 1 Main Visual FoxPro Window 2 Main Visual FoxPro Window 3 Main Visual FoxPro Window X,Y toolbar Command button Form Control 1 toobar1 command button toobar1 4 Command Group properties command button Caption = |< Name = cmdTop Click Event GO TOP THIS.Enabled = .F. THIS.Parent.cmdPrior.Enabled = .T. THIS.Parent.cmdBottom.Enabled = .T. THIS.Parent.cmdNext.Enabled = .T. THISFORMSET.Refresh Caption = < Name = cmdPrior Click Event SKIP -1

  • 75

    IF BOF() GO TOP THIS.Enabled = .F. THIS.Parent.cmdTop.Enabled = .F. ELSE THIS.Parent.SetAll("Enabled", .T. , "Commandbutton") ENDIF THISFORMSET.Refresh Caption = > Name = cmdNext Click Event SKIP IF EOF() GO BOTTOM THIS.Enabled = .F. THIS.Parent.cmdBottom.Enabled = .F. ELSE THIS.Parent.SetAll("Enabled", .T. , "Commandbutton") ENDIF THISFORMSET.Refresh Caption = >| Name = cmdTop Click Event GO BOTTOM THIS.Enabled = .F. THIS.Parent.cmdTop.Enabled = .T. THIS.Parent.cmdPrior.Enabled = .T. THIS.Parent.cmdNext.Enabled = .F. THISFORMSET.Refresh

  • 76

    Save

    CREATE FORM CUSTFORM command window CUSTFORM Data Environment data environment Add Other Add Table or View double click Samples double click data double click CUSTOMER.DBF cust_id CUSTFORM company CUSTFORM contact CUSTFORM form control command button CUSTFORM Caption = Exit Click Event THISFORM.Release form control Add myToolbar.VCX Visual Class toolbar1 toolbar save do form custform Visual Class Library class Event , Methods Properties (Events) ...(Object Oriented Program) event object event (event) Visual FoxPro

  • 77

    event download EVENTEST event load unload event DO FORM EVENTEST NAME FORMOBJ

    event Load event Init event object object object event Activate command window eventest event FORMOBJ.HIDE command windows FORMOBJ.SHOW event event When object cursor event When object Text1 () event object EVENTEST object text2 event When RETURN !EMPTY(THIS.PARENT.TEXT1.VALUE) object text1 object text2 event GotFocus focus objcet event

  • 78

    event When event When GotFocus focus Visual FoxPro event KeyPress keyboard event InteractiveChange object event Valid event object EVENTEST object text1 event Valid RETURN !EMPTY(THIS.PARENT.TEXT1.VALUE) object text1 object event LostFocus object event Click 1 enter object event event DoubleClick double click 2 () event event Destroy object object clear event Unload ACTIVATE SCREEN Main Visual FoxPro Window event event event control class event event event (Parameter) event Keypress Event LPARAMETERS nKeyCode, nShiftAltCtrl

  • 79

    n (numeric) a (array) c (charecter) l .T. , .F. (logical) d (date) f float o (object) t (datetime) y (currency) u unknow Visual FoxPro nKeyCode a () 97 ANSI Code CHR(nKeyCode) nShiftAltCtrl Shift, Ctrl Alt 1,2 4 0 Alt Ctrl 2+4=6 ActivateCell Event (grid control) nRow,nCol grid . cursor (Methods) object object object Circle Method _SCREEN.Circle(100,100,100) Object.Circle (nRadius, nXCoord, nYCoord [, nAspect]) CloneObject Method object properites,event method Object.CloneObject(NewName) Refresh Method

  • 80

    [[FormSet.]Object.]Refresh Object.Refresh Requery Method SQL ComboBox ListBox update ComboBox ListBox () Control.Requery Release Method , Object.Release Show Method , , [FormSet.]Object.Show([nStyle]) Visual FoxPro methods object ? (methods) method m_keypress object 1. Form Visual Class Library Class 2. New Method 3. Method Name Description

  • 81

    properties methods objcetName.MethodName cVarible = ObjectName.MethodName(cParameter,nParameter..) = ObjectName.MethodName FoxPro (Procedure) (Properties) Properties object properties AlwaysOnTop windows Object.AlwaysOnTop[ = lExpr] AutoCenter windows Object.AutoCenter [ = lExpr] Closeable Object.Closable[ = lExpr] WindowState 0 , 1 , 2

  • 82

    [Object.]WindowState[ = nState] WindowType 0 , 1 Object.WindowType[ = nType] object SetAll Container.SetAll(cProperty, Value [, cClass]) myForm.myOptionGroup.SetAll("Enabled",.F.) object properties Visual FoxPro properties properties 1. Form Visual Class Library Class 2. New Property 3. property Name Description

    properties container calculator r_lnewvalue = .T. r_ncaltxt = 0

  • 83

    r_coldmath = "+" author = "Program by Kasem K." . (Main Program) Visual FoxPro Project Manager Visual FoxPro sub-directory command window ! MD C:\MYAPP SET DEFAULT TO C:\MYAPP CREATE PROJECT MyProject main Visual FoxPro window main windows _SCREEN commnd window _SCREEN.Caption = '' && _SCREEN.Backcolor = rgb(192,192,192) && _SCREEN.Controlbox = .F. && control box _SCREEN.Controlbox = .T. _SCREEN.Closeable = .F. && close box _SCREEN.MaxButton = .F. && windows _SCREEN.MinButton = .F. && windows _SCREEN.Height = SYSMETRIC(2) && Main Visual FoxPro Window SYSMETRIC(2) set Windows set 640 x 480 480 Windows set _SCREEN.Width = SYSMETRIC(1) && Main Visual FoxPro

  • 84

    Windows _SCREEN.Visible = .F. && Main Visual FoxPro Window * .F. .T. Main Visual FoxPro Window (environment) Visual FoxPro Visual FoxPro CONFIG.FPW text editor modify command CONFIG.FPW Main Visual FoxPro Window _SCREEN Main Visual FoxPro Windows CONFIG.FPW SET CONFIG.FPW modify commmand CONFIG.FPW TITLE = && title DEFAULT = C:\MYAPP && default directory DATE = ANSI && yy.mm.dd CENTURY = ON && 4 yyyy ESCAPE = OFF && Esc DELETE = ON && HELP = OFF && help TALK = OFF && TMPFILE = C:\TEMP && directory tempolary file ( directory TEMP ) COMMAND = DO && _STARTUP COMMAND Main Visual FoxPro Window Application SCREEN = OFF CONFIG.FPW

  • 85

    Visual FoxPro CONFIG.FPW Project Manager MyProject 1. Project Manager Other 2. Text File Add 3. CONFIG.FPW Select file OK config ? config (parameter) -c build .exe myproject.exe MYPROJECT.EXE -CC:\MYAPP\MyConfig.FPW Visual FoxPro VFP.EXE -CC:\MYAPP\MyConfig.FPW (main program) () 1. () 2. () 3. READ EVENTS build application .EXE READ EVENTS help Visual FoxPro start event processing READ EVENTS CLEAR EVENTS READ EVENTS READ EVENTS main program CLEAR EVENT

  • 86

    (quit) READ EVENTS CLEAR EVENT 1. Code Project Manager 2. Programs New SET PROCEDURE TO UTILITY ON SHUTDOWN DO SHUT_DOWN ON ERROR DO errhand WITH ; ERROR( ), MESSAGE( ), MESSAGE(1),; PROGRAM( ), LINENO( ) SET CURSOR OFF DO FORM License NAME License INKEY(5) SET CURSOR ON DO Startup License.Release DO FORM Login READ EVENT DO Cleanup *** End of Program *** 3. save File Save As MAIN READ EVENTS CLEAR EVENTS 2 ON ERROR ON ERROR [Command] ON ERROR DO errhand WITH ERROR( ), MESSAGE( ), MESSAGE(1),PROGRAM( ), LINENO( ) errhand utility (procedure) errhand

  • 87

    1. Code Project Manager 2. Programs New ******************************************************************* * Procedure OnError ******************************************************************* PROCEDURE errhand PARAMETER merror, mess, mess1, mprog, mlineno ON SHUTDOWN messagebox(': ' + LTRIM(STR(merror)) + CHR(13) + ; ': ' + mess + CHR(13) + ; ': ' + mess1 + CHR(13) + ; ': ' + LTRIM(STR(mlineno)) + CHR(13) + ; ': ' + mprog + CHR(13) + ; 'Please contact your Vendor '+ CHR(13) + ; ' Visual FoxPro ' , 288,"") QUIT ENDPROC 3. save File Save As UTILITY ON SHUTDOWN ON ERROR [Command] close box ON SHUTDOWN DO SHUT_DOWN SHUT_DOWN UTILITY ******************************************************************* * Procedure ShutDown ******************************************************************* PROCEDURE Shut_Down LOCAL nAnswer nAnswer = messagebox("",292,"") IF nAnswer = 6

  • 88

    QUIT ENDIF ENDPROC (MENU) Visual FoxPro Project Manager Other Menus New command window CREATE MENU Enter

    * Visual FoxPro Version 5.0 Menu Visual FoxPro 2 Menu Shortcut Shortcut Menu MENU Menu dialog box New Menu Menu Designer Visual FoxPro Menu Quick Menu

  • 89

    Prompt title Result Command 1 Pad Name pad Bar# system menu bar Visual FoxPro Submenu submenu Procedure Create/Edit submenu Option Move Control Prompt Menu Level menu level Insert Insert Bar... Visual FoxPro (sysyem menu bar) Delete Preview

  • 90

    prompt File Create Prompt Result Customer Command DO FORM CUSTOMER Salesman Command WAIT WINDOWS 'NO PROGRAM' prompt Other Create Prompt Result Assign User Command DO FORM USERPRF prompt Exit Create Prompt Result Quit Command CLEAR EVENT Preview Generate Menu Generate... generate Visual FoxPro .MPR DO DO MENU.MPR Visual FoxPro SET SYSMENU TO DEFAULT generate .MPR Keyboard Shortcut shortcut Option Key Label shortcut Ctrl F, Alt F

  • 91

    Key Text (menu item) (menu title) (menu item) font menu item Option Skip For .F. FONT "AngsanaUPC",16 STYLE "BI" AngsanaUPC 16 B,I * font Preview generate DO .MPR Skip For (.T.) main visual foxpro window 1. command window CREATE MENU MENUFORM 2. Menu Menu Quick Menu 3. View General Option Top-Level Form 4. generate Menu Generate... 5. command window CREATE FORM FORMMENU 6.

  • 92

    form properties ShowWindows 2 - As Top-Level Form Init Event DO menuform.mpr WITH THIS,.T. Destroy Event RELEASE MENU Command1 properties Caption Cancel Click Event Thisform.Release save command window DO FORM FORMMENU SHORTCUT shortcut shortcut shortcut command window CREATE MENU MYSHORT Shortcut Insert Bar Clear Insert Paste Insert Cut Insert Copy Insert

  • 93

    Close

    generate Menu Generate... command windows MODIFY FORM FORMMENU Text1 RightClick Event DO MYSHORT.MPR Text2 RightClick Event DO MYSHORT.MPR save shortcut menu text1 darg short menu .. shortcut menu Control Textbox Visual Class Library ? MENU PAD POPUP BAR MENU File Edit View .... (menu bar)

  • 94

    Menu Designer _MSYSMENU Visual FoxPro MENU DEFINE MENU MenuBarName [BAR [AT LINE nRow]] [IN [WINDOW] WindowName | IN SCREEN] [FONT cFontName [, nFontSize]] [STYLE cFontStyle] [KEY KeyLabel] [MARK cMarkCharacter] [MESSAGE cMessageText] [NOMARGIN] [COLOR SCHEME nSchemeNumber | COLOR ColorPairList] DEFINE MENU example BAR AT LINE 1 MENU example PAD menu title File Edit PAD DEFINE PAD MenuTitle1 OF MenuBarName PROMPT cMenuTitleText [AT nRow, nColumn] [BEFORE MenuName2 | AFTER MenuName3] [NEGOTIATE LEFT | NEGOTIATE MIDDLE | NEGOTIATE RIGHT] [FONT cFontName [, nFontSize]] [STYLE cFontStyle] [KEY KeyLabel [, cKeyText]] [MARK cMarkCharacter] [SKIP [FOR lExpression]] [MESSAGE cMessageText] [COLOR SCHEME nSchemeNumber | COLOR ColorPairList]

  • 95

    DEFINE PAD syspad OF _MSYSMENU PROMPT '\

  • 96

    [RELATIVE] [SCROLL] [SHORTCUT] [TITLE cMenuTitleText] [COLOR SCHEME nSchemeNumber | COLOR ColorPairList] ON PAD convpad OF _MSYSMENU ACTIVATE POPUP conversion DEFINE POPUP conversion MARGIN RELATIVE COLOR SCHEME 4 popup convesion convpad _MSYSMENU BAR (menu item) New Open BAR DEFINE BAR nMenuItemNumber1 | SystemItemName OF MenuName PROMPT cMenuItemText [BEFORE nMenuItemNumber2 | AFTER nMenuItemNumber3] [FONT cFontName [, nFontSize]] [STYLE cFontStyle] [KEY KeyLabel [, cKeyText]] [MARK cMarkCharacter] [MESSAGE cMessageText] [SKIP [FOR lExpression]] [COLOR SCHEME nSchemeNumber | COLOR ColorPairList] DEFINE BAR 1 OF conversion PROMPT '\

  • 97

    skip SET SKIP OF form properties Init Event Destroy Event Menu Designer Skip for Prompt Option Skip for 1. command window CREATE MENU MENUS1 2. Menu Prompt Result File Submenu Exit Command SET SYSMENU TO DEFALUT option prompt File Prompt Option pad Pad Name PADFILE OK 3. prompt File Create Prompt Result Form1 Command DO FORM FORMS1 Form2 Command WAIT WINDOW 'TEST MENU' View Menu Options... Name POPFILE ( FILE) OK option prompt Form1 Prompt Option Bar# 1 Bar# Visual FoxPro 1 2,3... 4. generate Menu Generate... generate generate MODIFY COMMAND MENUS1.MPR

  • 98

    DEFINE PAD PADFILE OF _MSYSMENU PROMPT "File" COLOR SCHEME 3 KEY ALT+F, "" DEFINE PAD _s1r0u94fd OF _MSYSMENU PROMPT "Exit" COLOR SCHEME 3 KEY ALT+E, "" Pad Name Visual FoxPro _s1r0u94fd pad PADFILE View Menu Options... Popup DEFINE POPUP popfile MARGIN RELATIVE SHADOW COLOR SCHEME 4 Bar# DEFINE BAR 1 OF POPFILE PROMPT "Form1" ON SELECTION BAR 1 OF POPFILE DO FORMS1 BAR 5. command window CREATE FORM FORMS1

    form properties Init Event SET SKIP OF BAR 1 OF POPFILE .T. Destroy Event SET SKIP OF BAR 1 OF POPFILE .F. Command1 properties Caption Cancel Click Event Thisform.Release save

  • 99

    command window DO MENUS1.MPR skip SET SKIP OF... 4 SET SKIP OF... 4 skip SET SKIP OF MENU MenuBarName1 lExpression1 SET SKIP OF MENU _MSYSMENU .T. && skip SET SKIP OF MENU _MSYSMENU .F. && skip skip pad SET SKIP OF PAD MenuTitleName OF MenuBarName2 lExpression2 SET SKIP OF PAD PADFILE OF _MSYSMENU .T. && skip PAD SET SKIP OF PAD PADFILE OF _MSYSMENU .F.&& skip PAD skip popup SET SKIP OF POPUP MenuName1 lExpression3 SET SKIP OF POPUP POPFILE .T. && skip POPUP SET SKIP OF POPUP POPFILE .F. && skip POPUP skip SET SKIP OF BAR nMenuItemNumber | SystemItemName OF MenuName2 lExpression4 SET SKIP OF BAR 1 OF POPFILE .T. && skip SET SKIP OF BAR 1 OF POPFILE .F. && skip SKIP Expression .T. .F. .T. Skip .F. Skip skip Skip for OPTION (function) .T. .F. Exit skip Exit

  • 100

    MENUS1 MODIFY MENU MENUS1 prompt Exit Skip For _SCREEN.FORMCOUNT > 0 OK generate Menu Generate... _SCREEN.FORMCOUNT . .F. .T. DO MENUS1.MPR skip ? 2 command window MODIFY COMMAND CHKSKIP Enter ******************************************************************* * Function Check Skip Menu Item ******************************************************************* Function chkskip Para cFormname with _Screen nScreen= .Formcount for i = 1 to nScreen if upper(allt(.Forms(i).Name)) = upper(allt(cFormname)) return .T. endif endfor endwith return .F. save Ctrl+W

  • 101

    command window CREATE FORM FORMS2

    form properties Caption = skip Name = Forms2 && chkskip Command1 properties Caption Cancel Click Event Thisform.Release save MENUS1 MODIFY MENU MENUS1 Edit File Form2 WAIT WINDOW 'TEST MENU' DO FORM FORMS2 prompt Skip For CHKSKIP("Forms2") && Forms2 OK generate Menu Generate... DO MENUS1.MPR .

  • 102

    2 1. , , 2. 4 () (toolbar) Visual Class Libary (check error) 1. command windows SET DEFA TO C:\MYAPP MODIFY COMMAND MYPROJECT ( myproject download ) 2. Docs New New Form 3. form properites properties Caption = Icon = C:\myapp\bmp\thai.ico MaxButton = .F. MinButton = .F.

  • 103

    Top = 60 4. Form Control View Class ( ) Sub-Class MyToolbar ( Class Visual Class Library) Add mytoolbar Open toolbar1 YES (form set) Form Add New Form Remove Form Visual Class Library Form Control Visual FoxPro Standard 5. Data Environment... product Add Close 6. product Properties BufferModeOverried = 3 Order = prod_id BufferModeOveried (table) TABLEUPDATE() update TABLEREVERT() 1 2 .(lock record) (unlock record) 3 update 4 (unlock record) 5 update 5. Form Control View Class ( ) Sub-Class MyControl

  • 104

    Add mycontrol Open

    Properties Mtextbox1 ControlSource = Product.Prod_id InputMark = XXXXX Mtextbox2 ControlSource = Product.Name Mtextbox3 ControlSource = Product.Um InputMark = XXXXXXXXXX Mtextbox4 Alignment = 1 ControlSource = Product.UnitPrice InputMark = 9,999,999.99 Mtextbox5 Alignment = 1 ControlSource = Product.On_Hand InputMark = 9,999,999

  • 105

    (check error) 6. method Form New Method... msetenabledoff Add msetenabledon Add Close New Method Form New Property... property m_newrecord Add Close 7. Properties List box Form1 Formset1 Form1 Method msetenabledoff _Screen.Activeform.Setall("Enabled",.F.,"MtextBox") msetenabledon _Screen.Activeform.Setall("Enabled",.T.,"MtextBox") 8. Properties toolbar1 CmdEdit Click Event thisformset.form1.setall("Enabled",.T.,"Mtextbox") thisformset.form1.Mtextbox1.Enabled=.F. thisformset.setall("Enabled",.F.,"Mcommandbutton") thisformset.Toolbar1.cmdSave.Enabled=.T. thisformset.Toolbar1.cmdCancel.Enabled=.T. thisformset.form1.Mtextbox2.Setfocus _SCREEN.ActiveForm.Refresh CmdEdit Visual Class Library Visual Class Library 9. Properties Form1 Init Event thisform.SetAll("Enabled",.F. ,"Mtextbox") if recc() > 0 thisformset.toolbar1.cmdtop.click

  • 106

    endif Activate Event thisformset.toolbar1.Visible = .T. thisformset.form1.closable = .T. thisformset.toolbar1.Dock(0) select product thisformset.form1.refresh Deactivate Event thisformset.toolbar1.Visible = .F. . run 2 windows windows (invalid input) . 10. method Form New Method... mcheckerror Add Close New Method 11. mcheckerror Properties List box Form1 Formset1 Form1 Method mcheckerror With ThisFormset.FORM1 if ThisFormSet.m_newrecord if empty(.mTextBox1.Value)

  • 107

    .mTextBox1.setfocus messagebox("",288,"") return .f. endif endif if empty(.mTextBox2.Value) .mTextBox2.setfocus messagebox("",288,"") return .f. endif Endwith return .t. Valid Event (duplicate record) TABLEUPDATE() update TABLEUPDATE() .T. update TABLEUPDATE() .F. 12. Mtextbox1 Properties... Valid Event if .not. tableupdate() messagebox(' ' + allt(this.value) + '') return 0 endif 13. Save PRODUCT Valid Event return

  • 108

    .T. .F. Invalid Input Visual FoxPro return 0 .F. Data Session (data session) ? dBASE , Foxbase Visual FoxPro () Main Visual FoxPro customer.dbf customer.dbf customer.dbf Error ( properties Data Environment AutoClose Table .T.) (data session) 1. Default Data Session Visual FoxPro Defalut 2. Private Data Session ? Private Data Session (LAN) ? Form Properties Formset Properties DataSession Private Data session (Control) Form Designer

  • 109

    Form Refresh ? FOR I = 1 TO _SCREEN.FORMCOUNT _SCREEN.FORMS(I).REFRESH) ENDFOR DO FORM MyForm TO MyVar MyVar 1. Form New Properties MyReturnVar 2. Properties Windowtype 1 3. MyReturnVar ( Click Event Command Button ) THISFORM.MyReturnVar = THISFORM.TEXT1.Value 4. Form Properties Unload Method RETURN THISFORM.MyReturnVar DO FORM MyForm WITH MyVar 1. Init Event PARAMETER MyVar THISFORM.TEXT1.Value = MyVar && Text1 (Array) DO FORM MyForm WITH MyArray1 1. Form New Properties MyArray2(1) 2. Init Event PARAMETER MyArray1 DIMENSION MyArray2(ALEN(MyArray1)) &&

  • 110

    =ACOPY(MyArray1,THIS.MyArray2) && Label Control (Label) Label (Vertical) 1. Label Properties Caption ="T" + CHR(13) + "E" + CHR(13) + "S" + CHR(13) + "T" 2. Label Properties AutoSize .F. Label TextBox Control textbox textbox properties Format K SelectedBackColor 0,0,128 object Form Init Event Setall THISFORM.SetAll("Format","K","TextBox") THISFORM.SetAll("SelectedBackColor",RGB(0,0,128),"TextBox") textbox properties GotFocus Method IF NOT EMPTY(THIS.Value) KEYBOARD"{END}" KEYBOARD"{SHIFT+HOME}" ENDIF Grid Control Visual FoxPro Increment Search

  • 111

    Increment Search (Download) Visual FoxPro combo box list box (NAME) 1. MODIFY PROJECT MYPROJECT 2. (table) CUSTOMER DATA Databases -> MyDatabase -> Table 3. Table Designer Indexes Name NAME Type Regula Expression NAME OK Tools Options... Data Collating sequence Thai SET COLLATE TO "THAI" 1. Documents Form New New Form 2. Data Environment... CUSTOMER Add Close 3. CUSTOMER Properties Order = Name 4. Text box Properties FontName = MS Sans Serif High = 23 Width = 300 5. Grid Builder... CUSTOMER Name Cust_ID OK 6. properties Grid

  • 112

    DeleteMark = .F. FontName = MS Sans Serif GridLines = 0 Hight = 200 ReadOnly = .T. RecordMark = .T. ScrollBar = 2 Width = 350 7. properties Grid -> Column1 Resizeable = .F. Width = 280 8. properties Grid -> Column1 -> Header1 Alignment = 2 Caption = 9. properties Grid -> Column1 -> Text1 ForeColor = 255,255,255 BackColor = 0,0,128 10. properties Grid -> Column2 Resizeable = .F. Width = 50 11. properties Grid -> Column2 -> Header1 Alignment = 2 Caption = 12. properties Grid -> Column2 -> Text1 Enabled = .F. 13. method Text1 -> InteractiveChange Event SET NEAR ON SEEK ALLTRIM(THIS.VALUE) nRecno = RECNO() THISFORM.grid1.&cSetBack THISFORM.grid1.&cSetFore

  • 113

    THISFORM.REFRESH Grid1 -> AfterRowColChange Event nRecno = RECNO() THIS.REFRESH Grid1 -> Init Event PUBLIC nRecno , cSetBack , cSetFore nRecno = RECNO() cSetBack = 'setall("Dynamicbackcolor","IIF(RECNO()=nRecno,RGB(0,0,128),RGB(255,255,255))","Column")' && cSetFore = 'setall("Dynamicforecolor","IIF(RECNO()=nRecno,RGB(255,255,255),RGB(0,0,0))","Column")' && THIS.&cSetBack THIS.&cSetFore 14. save CUSTINQ (Download) Text Box , Combo Box , Edit Box 1. Documents Form New New Form 2. Data Environment... CUSTOMER Add Salesman Add Close 3. Data Enviroment Customer Salesman Delete 4. Grid Customer Data Environment Customer 5. Properties Form1 Hight = 300 Width = 600

  • 114

    6. Properties Grid1 FontName = MS Sans Serif RowHight = 30 Left = 15 Hight = 300 Width = 600 Properties 3 Column -> Header -> Control 7. Term_Day Edit Spinner Form Control ab| Term_Day Spiner 8. Term_Day Text Box Spinner Properties Column5 CurrentControl = Spinner1 9. Column6 ( Sales_ID) Combo Box Edit 7 Combo Box CurrentControl Combo1 10. Text1 Column5 Column6 properties dialogbox list box properties Text1 Column5 title

  • 115

    Delete (. )

    Text1 Column6 11. properties Spinner1 KeyboardHighValue = 999 KeyboardLowValue = 0 SpinnerHighValue = 999 SpinnerLowValue = 0 12. properties Combo1 BoundColumn = 1 ColumnCount = 2 ColumnWidths = 0,200 FontName = MS Sans Serif RowSource = Salesman.Sales_ID , Name RowSourceType = 6 header () 13. properties Grid1 HeaderHight = 45 14. properties Grid1 -> Column1 -> Header1 Caption = Spacebar 15. Label header

  • 116

    header properties Label BackStyle = 0 Caption = ="" + CHR(13) + "Customer ID" 16. save CUSTGRD (Download) Visual FoxPro ... (CUSTOMER) Shortcut Menu (record) (message) confirm Save Cancel Error Duplicate 1. shotcut menu ( command button ) command window CREATE MENU CUSTGRD1 Shortcut

    Edit Append New Record APPEN BLANK GO BOTT _Screen.Activeform.lSkip = .T. _Screen.Activeform.lAppend = .T.

  • 117

    _Screen.Activeform.Refresh Option Append New Record Skip for _Screen.ActiveForm.LSkip && skip LSkip .T. Edit Delete A Record IF MESSAGEBOX(" " + Customer.Cust_ID, 292, "") Delete =Tableupdate(.T.) _Screen.ActiveForm.Refresh ENDIF Option Delete A Record Skip for _Screen.ActiveForm.LSkip && skip LSkip .T. Menu Generate... Ctrl + W Save 2. shotcut menu command window CREATE MENU CUSTGRD2 Shortcut

    Edit Save =Tableupdate(.T.) _Screen.ActiveForm.LSkip = .F. _Screen.Activeform.lAppend = .F. Edit Cancel =Tablerevert(.T.) _Screen.ActiveForm.LSkip = .F. _Screen.Activeform.lAppend = .F.

  • 118

    Menu Generate... Ctrl + W Save 3. shortcut menu CUSTGRD MODIFY FORM CUSTGRD 4. Data Environment... table CUSTOMER Properties... BufferModeOverride = 5 TABLEUPDATE() tabel buffer 5. property Form New Property... nRecNum Add nWhatRow Add LAppend Add LSkip Add Close 6. method Form New Method... mShortcut Add Close 7. Properties Form nRecNum = 0 nWhatRow = 0 LAppend = .F. LSkip = .F. mShortcut cChange = GetFldState(-1,"Customer") IF AT('2', cChange) > 0 .OR. AT('4', cChange) > 0 DO CUSTGRD2.MPR ELSE DO CUSTGRD1.MPR ENDIF 8. Form Init Event SET DELETE ON

  • 119

    (record) 9. Grid1 AfterRowColChange LPARAMETERS nColIndex IF ThisForm.lAppend ThisForm.nWhatRow = This.ActiveRow ThisForm.lAppend = .F. ELSE lMov = .F. IF ThisForm.nWhatRow # This.ActiveRow ThisForm.nWhatRow = This.ActiveRow nHold= RECNO() GO ThisForm.nRecNum cChange = GetFldState(-1,'Customer') IF AT('2', cChange)>0 .or. AT('4',cChange) > 0 This.Refresh lMov = .T. IF MessageBox("Update Record",4)= 6 =TableUpdate(.T.) ELSE =TableRevert(.T.) ENDIF ThisForm.lSkip = .F. ELSE IF AT('4',cChange) = 0 .and. AT('1',cChange) = 0 = TableRevert(.T.) ThisForm.nRecNum = nHold ThisForm.lSkip = .F. ENDIF ENDIF GO nHold IF lMov lMov =.F.

  • 120

    ENDIF ENDIF ENDIF This.Refresh record (table buffer) (TABLEUPDATE) Visual FoxPro GETFLDSTATE() GETFLDSTATE(cFieldName | nFieldNumber [, cTableAlias | nWorkArea]) 1 4 1 = 2 = 3 = 4 = nFieldNumber -1 121121 command window SET MULTILOCKS ON USE CUSTOMER =CURSORSETPROP("BUFFERING",5,"CUSTOMER") GO 2 DELETE ?GETFLDSTATE(-1,"CUSTOMER") && 2111111 GO 1 REPLACE NAME WITH "abc" ?GETFLDSTATE(-1,"CUSTOMER") && 1121111 NAME ?GETFLDSTATE("NAME") && 2 NAME

  • 121

    APPEN BLANK ?GETFLDSTATE(-1) && 3333333 TABLEREVERT(.T.) && 9. Grid1 BeforeRowColChange IF EOF() GO BOTT ENDIF ThisForm.nRecNum = RECNO() 10. Grid1 Init ThisForm.nRecNum = RECNO() 11. Grid1 RightClick =thisform.MShortcut() 12. Grid1 Column1->Text1 RightClick =thisform.MShortcut() 13. File Save As CUSTGRD1 Save Duplicate Record IF .NOT. TABLEUPDATE() (one to meny) Download one to meny (invoice) (table) (relation) command windows CLOSE ALL OPEN DATABASE MYDATABASE CREATE FORM INVOICE property Load Event SET DELETE ON Property Form New Property LNew 1. Data Enviroment... 2. Data enviroment Add... INV_HEAD Add

  • 122

    INV_DTL Add CUSTOMER Add PRODUCT Add Close 3. Data Environment Del keyboard 4. INV_HEAD INV_DTL INV_NO INV_HEAD CUSTOMER CUS_ID INV_DTL PRODUCT PROD_ID 5. (parent) (child) INV_NO INV_HEAD INV_NO INV_DTL CUS_ID INV_HEAD CUS_ID CUSTOMER PROD_ID INV_DTL PROD_ID PRODUCT (index) (child table)

    6. property Properties... property

  • 123

    INV_HEAD BufferModeOverried = 2 Order = INV_NO INV_DTL BufferModeOverried = 4 Order = INV_NO CUSTOMER Order = CUST_ID PRODUCT Order = PROD_ID

    6. Command Button property Caption = Name = CmdAppend Click Event

  • 124

    thisform.lNew = .T. sele inv_head go bott nInv_No = inv_head.inv_no + 1 INSERT INTO INV_HEAD (inv_no,date) ; VALUES (nInv_no,date()) with thisform .txtDate.Enabled = .T. .txtCust_id.Enabled = .T. .txtDate.setfocus .cmdAppend.Enabled = .F. .cmdChange.Enabled = .F. .cmdSave.Enabled = .T. .cmdCancel.Enabled = .T. .Grid1.Enabled = .T. .Grid1.Column1.Text1.Enabled = .F. .Grid1.Column5.Text1.Enabled = .F. .cmdAppendItem.Enabled = .T. .cmdDeleteItem.Enabled = .T. .refresh endwith 7. Command Button property Caption = Name = CmdChange Click Event thisform.lNew = .F. with thisform .txtDate.Enabled = .T. .txtCust_id.Enabled = .T. .txtDate.setfocus .cmdAppend.Enabled = .F. .cmdChange.Enabled = .F.

  • 125

    .cmdSave.Enabled = .T. .Grid1.Enabled = .T. .Grid1.Column1.Text1.Enabled = .F. .Grid1.Column5.Text1.Enabled = .F. .cmdAppendItem.Enabled = .T. .cmdDeleteItem.Enabled = .T. .refresh endwith 8. Command Button property Caption = Name = CmdSave Enabled = .F. Click Event sele inv_head =tableupdate(.F.) sele inv_dtl =tableupdate(.T.) sele inv_head with thisform .txtDate.Enabled = .F. .txtCust_id.Enabled = .F. .combo1.setfocus .cmdAppend.setfocus .cmdAppend.Enabled = .T. .cmdChange.Enabled = .T. .cmdSave.Enabled = .F. .cmdCancel.Enabled = .F. .cmdAppendItem.Enabled = .F. .cmdDeleteItem.Enabled = .F. .Grid1.Enabled = .F. .refresh endwith

  • 126

    9. Command Button property Caption = Name = CmdCancel Enabled = .F. Click Event sele inv_head =tablerevert(.T.) sele inv_dtl =tablerevert(.T.) sele inv_head if eof() .and. Thisform.lNew GO BOTT endif with thisform .txtDate.Enabled = .F. .txtCust_id.Enabled = .F. .combo1.setfocus .cmdAppend.setfocus .cmdAppend.Enabled = .T. .cmdChange.Enabled = .T. .cmdSave.Enabled = .F. .cmdCancel.Enabled = .F. .cmdAppendItem.Enabled = .F. .cmdDeleteItem.Enabled = .F. .refresh endwith 10. Data Environment INV_HEAD INV_NO, DATE, CUST_ID 11. NAME CUSTOMER Properties object txtInv_no property Enabled = .F.

  • 127

    txtDate property Enabled = .F. Format = E txtCust property Enabled = .F. Valid Event =SEEK(this.Value,"Customer") thisform.refresh txtName property Enabled = .F. 12. NAME CUSTOMER property Enabled = .F. 13. Data Environment INV_DTL INV_DTL property AllowHeaderSizing = .F. AllowRowSizing = .F. DeleteMark = .F. Enabled = .F. ScrollBars = 2 SplitBar = .F. 14. column (PROD_ID), (NAME), (QUANTITY