F1
About F1Course ScheduleOther ServicesSite MapContactHome

Visual FoxPro

 
Exchange Server
Office (inc Access)
SQL Server
Visual Studio .NET
Windows
Web Development
Visual FoxPro
Programming
Business
Knowledge Management
Certification
Learning Options
Extracts from F1’s unique 5 day course VFP 6.0 Intensive
(Print sample notes in PDF format)   What is PDF?

This extract covers a walkthrough 'Creating A Simple Form With Buttons, Labels and TextBoxes'. The Visual FoxPro 6.0 course covers all topics necessary to help you build quality VFP systems.

The object of the walkthrough is to create the above form. When the Set Title Command Button is selected, the text in the Title: box is copied to the forms’ title (caption).

Create a New Form

  1. Make sure the default directory in the Options window is pointing to the Course directory.
  2. Create a new Form by selecting the File...New menu item. Select the Form File Type option button and click the New File button. The Form Designer will appear.

  3. Place Controls on the Form

  4. Click once on the LABEL icon in the forms toolbar, then click once on the empty form where the TITLE: label is to appear.
  5. Click once on the TEXT BOX icon in the forms toolbar, then click once on the empty form where the text input field for title is to appear. Drag one of the sizing handles (black dots) around the text box to increase its’ length to roughly twice as long as it initially appears.
  6. Click once on the COMMAND BUTTON icon in the forms toolbar, then click once on the empty form where the SET TITLE button is to appear.
  7. Again, click once on the COMMAND BUTTON icon in the forms toolbar, then click once on the empty form where the CLOSE button is to appear.

  8. Set Properties for the Controls

  9. Bring up the properties window. Either use the VIEW menu and select PROPERTIES, or right-click on the form and select PROPERTIES from the resulting shortcut menu.
  10. Select the object Label1.
  11. In the properties window, set the following values:
  12. AutoSize=.T.

    Caption=Title

  13. For the first command button (Command1) set the Caption property to Set Title.
  14. For the second command button (Command2) set the Caption property to Close (you can use \<Close as in Fox 2.x to set a button hot-key).
  15. Click on the form background, this causes the property window to display the form properties. Now set the forms’ AutoCenter property to .T.
  16. The \< can be used in the Caption for a label to allow a hotkey to set the focus on the control placed after the label. Use the View-Tab Order to rearrange the objects tabbing order accordingly.

    Add Code to Make the Buttons Work

  17. Double-click on the Set Title command button. In the resulting code window, enter:
  18. ThisForm.Caption = ThisForm.Text1.Value

  19. Now close the code window.
  20. Double-click on the Close command button. In the resulting code window, enter:
  21. Release ThisForm

    or

    ThisForm.Release()

  22. Now close the code window.
  23. Select from the FILE menu the SAVE AS option. Save the form as SO_FORM01 ensuring it goes into the Training directory.

Run the Form

 Click on the RUN icon in the standard toolbar.

Type some text into the Title: text box.

Click on the Set Title button. Notice the forms’ title changes.

Click on the Close button to exit.

To re-run the form, Right Click on the form in the designer or use the DO FORM command in the command window.

 

The next extract covers a walkthrough concerning the use of the Debug and Trace Windows

Write and save the following two very simple programs.. Together, these will then be used to look at features of the Trace and Watch and Debug Out windows.

Save the first program as test1.prg:-

*

* TEST1.PRG

LOCAL x, i, test

x=1

DECLARE test(1)

STORE SPACE(0) TO test

DO test2 WITH m.x, test && Passes by reference

DEBUGOUT PROGRAM()

FOR m.i=ALEN(test) TO 1 STEP -1

DEBUGOUT test(m.i)

ENDFOR

 

PROCEDURE test2

LPARAMETERS m.y, test2

LOCAL m.x

m.x=m.y+1

=test3(@m.x, @test2) && Function call

RETURN

 

PROCEDURE test3

LPARAMETERS m.y, test3

LOCAL m.x

m.x=m.y+1

DO test4 WITH m.x, test3

RETURN

 

PROCEDURE test4

LPARAMETERS m.y, test4

LOCAL m.x

m.x=m.y+1

DEBUGOUT PROGRAM() && Message the Program name

DEBUGOUT callstack( @test4 )

RETURN

 

 

Save the second program as callstack.prg

*

* Callstack.prg – callstack reporting function...

LPARAMETERS stackarray

LOCAL x, retval

STORE 1 TO x

DO WHILE LEN(SYS(16,x)) # 0

IF SYS(16) # SYS(16,x) && Don't report callstack

DECLARE stackarray(x)

STORE SYS(16,x) TO stackarray(x)

ELSE

EXIT && Exit if callstack

ENDIF

STORE x+1 TO x

ENDDO

retval=IIF(TYPE('stackarray(1)')='L',0,ALEN(stackarray))

RETURN m.retval

 

Close both programs and bring up the Debugger (from the Tools menu pad).

  1. From the File menu or the open button, open test1.prg.
  2. Right click on the Trace window and set the Trace Between Breaks feature on.
  3. Click the Do option on the Debug menu or the Resume button on the toolbar, then click on the STEPINTO button {¯ }. This should step one line at a time through the code. Hover over a variable or field to see its current value.
  4. Ordinarily the Trace window runs through the code too quickly. Choose ‘Throttle’ from the Debug menu of the Trace window, and input a throttle value of 0.5 seconds. Close the Throttle window and click the Resume button on the toolbar. Press ESCAPE again to suspend the code. Now choose throttle again and clear the throttle value.
  5. To step line by line through the code, click the STEP INTO button. Keep clicking STEP until you are in callstack.prg . Now click the STEP OUT button. The OUT option is useful for running code from a sub-routine (essentially a program called by the one you are tracing) without tracing that code. Alternately, you can avoid ‘falling into’ the routine in the first place. Click STEP until the ‘Do test2.prg’ line is highlighted. Now click the STEP OVER button. This allows you to run the subroutine without tracing (as with OUT), but avoiding ‘falling in’ in the first place.
  6. Now activate the Watch, Locals, Call Stack and Debug Output windows , and type in PROGRAM(),sys(16), x, and y in the Watch expression and press Return. The expression and the name of the currently active program should now appear in the window along with the data type. Double click on the ‘bar’ to the left of the watch expressions. This puts a breakpoint on the value returned. Click resume on the Trace window and notice how the program will suspend with an appropriate message window when the value (with the break point) in the Watch window changes.
  7. Before the program test1.prg finishes it outputs certain information to the Output window. Can you make sense of what it is telling you ?
  8. Finally choose Cancel from the Debug menu or the Cancel button on the toolbar to end the program. Then choose Breakpoints from the Tools menu, and clear them down.
  9. Breakpoints can be put into a program from the Trace window, the program can be loaded or resumed from the main window). When the break point is activated, the program will suspend and the Debugger can be brought forward
Adobe Acrobat (PDF) Reader is a free application which enables people to view and print flyers just as they would have been professionally printed .You can down load it from the site below:

Adobe Acrobate Reader      Table of all F1 Flyers in PDF format


© F1 Computing Systems 2001