Visual Foxpro 6 Programmer's Guide - Ebook download as PDF File .pdf), the Class Designer, see Chapter 3, Object-Oriented Programming, in this book. Basics of Visual FoxPro Programming - Free download as Powerpoint Presentation .ppt /.pptx), PDF File .pdf), Text File .txt) or view presentation slides online. PDF Drive is your search engine for PDF files. As of today we have 77,, eBooks for you to download for free. No annoying ads, no download limits, enjoy .
|Language:||English, Spanish, German|
|PDF File Size:||9.23 MB|
|Distribution:||Free* [*Regsitration Required]|
This book is designed to take you into the world of Visual FoxPro. .. Studio is to provide the programming and database tools to develop software that is. Part of the Communications in Computer and Information Science book series Visual Foxpro Programming physical education college two-stage method. 0 3D Max tutorial book PDF download Microsoft Windows Professional Resource Kit Foxpro Programming Handbook download Book The Pinter Visual.
Now i want to learn visual foxpro from basic itself Actually i have forgotton some commands. Now i am working in Goverment Aided Educational Institution near kanniyakumari and i want to develop software for our school students. Please help me. I think the same things that were recommended in are still good choices. Certainly the Garfield Hudson videos are still around and you can still buy ebook versions of the Hentzenwerke books.
You'll find lots of articles about VFP online. Here are some places to start: For every expert, there is an equal and opposite expert. Does anything like this exist for the older version of Visual FoxPro 6.
The content you requested has been removed. Ask a question. Quick access. Search related threads. Remove From My Forums. Asked by: Visual FoxPro.
Visual FoxPro General. Visual FoxPro General https: NET interoperability, and more. Sign in to vote. I'm a level 1 VB programmer. I've been using MS Access as my back end database for all my projects. After you open the program, you can make changes. When you finish making your changes, be sure to save the program. Running Programs After you create a program, you can run it. To run a program G If the program is contained in a project, select it in the Project Manager and choose Run.
From the list of programs, select the program to run, then choose Do. The Report Designer allows you to create complex and customizable reports by integrating code into the report file. To take advantage of the full power of Visual FoxPro, you need to use these design tools. Basic Programming Concepts When you program, you store data and manipulate it with a series of instructions. The data and data storage containers are the raw materials of programming.
The tools you use to manipulate this raw material are commands, functions, and operators. Storing Data The data you work with probably includes amounts of time, money and countable items, as well as dates, names, descriptions, and so on.
Each piece of data is a certain type: You could work directly with this data without storing it, but you would lose most of the flexibility and power of Visual FoxPro. Visual FoxPro provides numerous storage containers to extend your ability to easily manipulate data. Data types determine how data is stored and how it can be used.
Some of the primary data types in Visual FoxPro are listed in the following table: Data Types Type Numeric Examples 3. Data Containers Data containers allow you to perform the same operations on multiple pieces of data. For example, you add the hours an employee has worked, multiply them by the hourly wage, and then deduct the taxes to determine the amount of pay the employee has earned.
If you store this information in containers, and perform the operations on the containers, you can just replace the old data with new data and run the same program again. This table lists some of the main containers for data in Visual FoxPro: Multiple rows of predetermined fields, each of which can contain a predefined piece of data. Tables are saved to disk. Multiple elements of data stored in RAM.
Manipulating Data Containers and data types give you the building blocks you need to manipulate data. The final pieces are operators, functions, and commands. Using Operators Operators tie data together. Here are the most common operators in Visual FoxPro. Result Prints. Prints 25 Prints 5. Note A question mark? Remember that you must use the same type of data with any one operator. The following statements store two numeric pieces of data to two variables. The variables have been given names that start with n so we can tell at a glance that they contain numeric data, but you could name them with any combination of alphanumeric characters and underscores.
The variables have been given names that start with c to indicate that they contain character data. For example, STR returns the character equivalent of a numeric value and VAL returns the numeric equivalent of a character string of numbers.
These functions and LTRIM , which removes leading spaces, enable you to perform the following operations: For example, the functions STR and VAL , used in the previous section, return character and numeric values, respectively.
As with all functions, these return types are documented along with the functions. There are five ways to call a Visual FoxPro function: G Assign the return value of the function to a variable. The following line of code stores the current system date to a variable named dToday: The following line of code prints the current system time in the active output window: TIME Call the function without storing the return value anywhere.
The following function call turns the cursor. SYS Embed the function in another function.
The following line of code prints the day of the week: Some other examples of functions used in this chapter are: Returns the name of a field. Returns the number of characters in a character expression. Returns the number of records in the currently active table. Returns the specified number of characters from a character string, starting at a specified location in the string. Using Commands A command causes a certain action to be performed.
Each command has a specific syntax which indicates what must be included in order for the command to work. There are also optional clauses associated with commands that allow you to specify in more detail what you want. For example, the USE command allows you to open and close tables: Description Closes the table in the current work area. Some examples of commands used in this chapter are: Replaces the value stored in record field with a new value.
Positions the record pointer to a specific location in the table. These commands allow conditional branching and looping, two very powerful programming tools.
The following program illustrates conditional branches and loops. These concepts are described in more detail after the example. The following sample program accomplishes this task. This program assumes that a table with a numeric field named salary is open in the current work area. Each time the code is executed, the record pointer moves to the next record in the table. The semicolon ; after WITH indicates that the command is continued on the next line. End of the conditional IF statement.
End of the code that is executed for each record in the table. This example uses both conditional branching and looping commands to control the flow of the program. Conditional Branching Conditional branching allows you to test conditions and then, depending on the results of that test, perform different operations. There are two commands in Visual FoxPro that allow conditional branching: In the example program, the IF command is used to distinguish between two states: Different actions are taken depending on the state.
In the following example, if the value stored in the variable nWaterTemp is less than , no action is taken: Comments help the programmer remember what each segment of code is designed to do, but are ignored by Visual FoxPro.
Looping Looping allows you to execute one or more lines of code as many times as you need to. There are three commands in Visual FoxPro that allow looping: G SCAN Use SCAN when you are performing a series of actions for each record in a table, as in the example program just described. The SCAN loop enables you to write the code once and have it executed for each record as the record pointer moves through the table.
Use FOR when you know how many times the section of code needs to be executed. For example, you know there are a specific number of fields in a table. You might not know how many times the code will have to execute, but you know when it should stop executing.
You would have a problem the first time you tried to add a person who had the same initials as someone else already in your table. To solve the problem, you could add a number to the initials. The next person with the same initials, Margaret Sun, would be MS1. If you then added Michelle Smith to the table, her identification code would be MS2. See if there is another person in the table with the same initials.
Prepare a fresh suffix and append it to the end of the initials. The Process of Programming When you understand the basic concepts, programming is an iterative process. You go through the steps many times, refining your code as you go.
When you are starting out, you test frequently, using a lot of trial and error. The more familiar you become with the language, the more quickly you can program and the more preliminary testing you can do in your head.
The basic programming steps include: G Stating the problem. G Breaking the problem down into discrete elements. G Constructing the pieces. G Testing and fixing the pieces. G Assembling the pieces. Here are some things to remember when you are getting started: G Clearly delineate the problem before trying to solve it.
G Break the problem down into manageable steps instead of trying to solve the whole problem at once. G Test and debug sections of code as you develop. Test to see if the code does what you want it to do. Debugging is the process of finding and fixing the problems that prevent the code from doing what you want it to do.
G Refine your data and data storage to make it easier to manipulate the data through program code. This often means structuring your tables properly. The rest of this section traces the steps in constructing a small Visual FoxPro program. Stating the Problem Before you can solve a problem, you need to formulate it clearly. Suppose you get a lot of data from various sources. Though most of the data is strictly numeric, some data values contain dashes and spaces in addition to numbers.
You should remove all the spaces and dashes from those fields and save the numeric data. Instead of trying to remove spaces and dashes from the original data, you could formulate the goal of the program as: Goal Replace the existing values in a field with other values that contain everything from the original values except the spaces and dashes.
This formulation avoids the difficulty of manipulating a string of characters whose length keeps changing as you work with it. Breaking the Problem Down Because you have to provide specific instructions to Visual FoxPro in terms of operations, commands, and functions, you need to break the problem down into discrete steps. The most discrete task for the example problem is to look at each character in the string.
After you look at a character, you need to check to see if it is a dash or a space. At this point, you might want to refine the statement of the problem. What if you get data later that contains open and closed parentheses? What if you want to get rid of currency symbols, commas, and periods? The more generic you can make the code, the more work you can save yourself later; the whole point is to save work.
Here is a formulation of the problem that works with a much greater variety of data: Refined Goal Replace the existing values in a field with other values that contain only the numeric characters from the original values.
With this formulation, you can now restate the problem at the character level: When you have constructed a string that contains only the numeric elements of the initial string, you can replace the first string and move on to the. To summarize, the problem breaks down into these pieces: Look at each character. Decide if the character is numeric or not.
If it is numeric, copy it to the second string. When you have gone through every character in the original string, replace the original string with the numeric-only string.
Repeat these steps for all the records in the table. Constructing the Pieces When you know what you need to do, you can start to formulate the pieces in terms of Visual FoxPro commands, functions, and operators. Since the commands and functions will be used to manipulate data, you need some test data to work with. You want the test data to resemble the actual data as closely as possible. For this example, you can store a test string to a variable by entering the following command in the Command window: For a list of functions that can be used to manipulate strings, see Character Functions.
You will find three functions that return specific sections of a string: To do the same thing a number of times, use a loop. Since the test string has a specific number of characters 14 , http: Now would be a good time to create a new program. To create a new program 1. Type the following command in the Command window: In the window that opens, type the following lines of code: To run a program 1. If a Save dialog box appears, choose OK.
When you run this program, the individual characters in the test string are printed on separate lines in the main Visual FoxPro window. Testing Part of the Program. Type the following commands in the Command window: Decide if the Character is Numeric After you have fetched a single character from the string. You can now look at each character in the string.
Copy it to the Second String Now that you can look at the characters and determine whether they are numeric. Introduction to Programming The first task has been accomplished. If the Character is Numeric. From this output. You need a way to adjust for varying string lengths. Introduction to Programming numeric values: To create the variable. But if you change the test string as you are testing the pieces.
Type the following command in the Command window and run the program again: You can then manipulate the variable without having to repeat the calculation or evaluation. Use LEN to return the number of characters in a string.
If you substitute this command in the FOR loop. The FOR loop tried to execute 14 times. The following line of code can be used each time a number is encountered to add the number to the second string: When you have selected a table to use. Such a table could contain a single character field called TestField and four or five records: TestField Contents 89 0 22 When you substitute the name of the field for the name of the test string.
Introduction to Programming correctly with both test strings: When the record pointer is on each of the records. TestField http: Making the Program More Robust A robust program does what you want it to. G A table is open in the current work area. G The table has a character field named TestField. Use the following line of code to do this: Introduction to Programming?
ENDSCAN Output 89 0 22 Testing the Whole Program Instead of printing the string at the end of the program. The example program does what you want it to do. Using Procedures and User-Defined Functions Procedures and functions allow you to keep commonly-used code in a single place and call it throughout your application whenever you need it.
The most limiting feature of this program is that you can use it for only one field. Comments This variable determines if the necessary conditions exist for the program to work. The conversion section of the program is executed only if a character field named TestField is present in the currently active table.
This section of code goes through every field in the current table until it finds a character field named TestField. If you want to remove the non-numeric characters from a field other than TestField. This makes your code easier to read and easier to maintain because a change can be made once in the procedure rather than multiple times in your programs.
If no field matches the criteria. Converting the program to a function. The conversion code. As soon as the correct field is found. In Visual FoxPro. For example. You cannot have normal executable program code included in a program file following procedures and functions.
Passing Parameters Code Comments http: Parameters work identically in a function. Sending Values to a Procedure or Function To send values to procedures or functions. G Use the DO command.
For example: To send a value as a parameter to this procedure or to a function. The following procedure. DO myproc -orInclude a set of parentheses after the function name. If you include your procedures and functions in a separate program file.
When you use DO.
You can send multiple values to a procedure or function by separating them with commas. Calls a function and passes a copy of a character variable or literal string. By default. Prints the value returned by the function in the active output window. Note If you call a procedure or function without using the DO command.
You can use the TYPE function to make sure the value your function receives is the right type. Visual FoxPro generates an error message. But if a procedure expects more parameters than it receives. Because there is no way to tell whether the last parameter was set to false. For example.. The example in the previous section. To learn about designing forms with the Form Designer. In addition to allowing you to use this code in multiple situations.
For more information on programming with an object-oriented approach. Object-Oriented Programming. Creating Forms. All rights reserved. Find support options. G Planning the Application Careful planning saves time.
Developing an Application Chapter 2: Queries and reports allow users to retrieve information from their data. If you have twenty or thirty records in a table. If you have twenty or thirty thousand records. Chapter An order entry form. Optimizing Applications. Using Controls. Common User Activities Even if your end users are working with customers. Who will be using the application?
What is the center of user activity? How large a data set will you conceivably be working with? Will back-end data servers be used or will the data be exclusively local to a single user or multiple users over a network? Consider these factors before getting too far into the project. This chapter discusses: Some of the design decisions you make will impact how you create elements of the application. You may also want to adjust the way you allow users to move through the data. The more you involve your end users in the planning process.
No matter how carefully you plan. Chapter 8. Remote Data If your application deals with remote data. Visual FoxPro makes it easy to program for shared access. Developing an Application table records. Developing International Applications. And nobody writes bug-free code all the time. Programming for Shared Access. End-user expectations or commitments can also change. International Considerations If you know your application will be used only in a single-language environment.
Single User vs. Creating Views. Overview of the Process The process of creating an application is largely iterative. Since no two applications are exactly the same. The process of creating an application http: Local vs. You can make the framework yourself in the Windows Explorer and the project in the Project Manager. For backward compatibility. This new Application Wizard opens the Application Builder so you can further customize a project and components you start in the wizard.
Starting Development After you have planned which components you need in your application. Developing an Application In addition to taking the big picture into account in your planning stage.
You can create reports and queries so that users can extract useful information from their data. For information about compiling applications. For detailed information about how to use the Project Manager. View and modify your tables and databases easily. Add descriptions for the components in your application. G Modify and run pieces of your application forms. Getting Started. Drag-and-drop elements between projects. G G G G Drag classes between class libraries.
G Drag classes. Compiling an Application. The user interface consists primarily of forms. Designing Menus and Toolbars. Chapter 6. Utilizing Visual FoxPro controls in your forms is discussed in Chapter Chapter 9. You can set up your database and determine what the relationships are between tables. You can create classes in a program file.
Chapter 3. Reports allow users to print full. Developing an Application Creating Databases Because a database application is so dependent on the underlying data. You can have a very clean class model. You can associate all the functionality in your application with controls or menu commands in the interface.
In addition to making code more manageable and easier to maintain. Creating Classes You can create a robust.
See Chapter What they see is the interface you provide. Designing Databases. A sound database foundation makes development work much easier. Creating Databases. Providing Access to Functionality User satisfaction will be strongly influenced by the interface you provide for the functionality of your application. Chapter 5. You might not ever have to create a class.
Working with Tables. Adding Queries and Reports. Testing and Debugging Applications. Developing an Application ActiveX controls and automation allow your application to share information and functionality with other applications.
It's a good idea to test and debug as you go. Chapter 12 of this book. Adding OLE. If you create a form. Testing and Debugging Testing and debugging is something most developers do at each step in the development process.
Object-oriented programming is largely a way of packaging code so that it can be reused and maintained more easily. G More compact code. The class determines the characteristics of the object. The object-oriented Visual FoxPro language extensions provide you with a great deal of control over the objects in your applications.
Instead of thinking about program flow from the first line of code to the last line of code. Classes and Objects: The Building Blocks of Applications Classes and objects are closely related.
G Less complexity when integrating code from different files into an application. You manipulate these objects through their properties. A class contains information about how an object should look and behave. The electrical schematic and design layout of a telephone. These extensions also make it easier to create and maintain libraries of reusable code.
The primary package is called a class. G Easier incorporation of code into applications without elaborate naming schemes. The object. A class is the blueprint or schematic of an object. Object-Oriented Programming Chapter 3: Object-oriented design and object-oriented programming represent a change in focus from standard procedural programming. Objects Have Properties An object has certain properties, or attributes.
For example, a phone is a certain color and size. When you put a phone in your office, it has a certain position on your desk. The receiver can be on or off the hook. Objects you create in Visual FoxPro also have properties that are determined by the class the object is based on.
These properties can be set at design time or at run time. For example, some of the properties that a check box can have are listed in the following table: Specifies whether the check box can be chosen by a user. The color of the caption text. The position of the left side of the check box. How the mouse pointer looks when over the check box. The position of the top of the check box. Specifies whether the check box is visible. Objects Have Associated Events and Methods Each object recognizes and can respond to certain actions called events.
An event is a specific and predetermined activity, initiated by either a user or the system. Events, in most cases, are generated by user interaction. For example, with a phone, an event is triggered when a user takes the receiver off the hook.
Events are also triggered when the user presses the buttons to make a call. In Visual FoxPro, user actions that trigger events include clicks, mouse moves, and key presses. Initializing an object and encountering a line of code that causes an error are system-initiated events.
Methods are procedures that are associated with an object. Methods are different from normal Visual FoxPro procedures: Events can have methods associated with them. For example, if you write method code for the Click event, that code is executed when the Click event occurs. Methods can also exist independently of any events. These methods must be explicitly called in code.
The event set, while extensive, is fixed. The method set, however, is infinitely extendible. The following table lists some of the events associated with a check box: User selects the check box by clicking it or tabbing to it. User selects another control. The following table lists some of the methods associated with a check box: Method Description. The value of the check box is updated to reflect any changes that may have occurred to the underlying data source.
The focus is set to the check box just as though the user had pressed the TAB key until the check box was selected. See Chapter 4, Understanding the Event Model, for a discussion of the order in which events occur. Understanding Classes in Visual FoxPro All of the properties, events, and methods for an object are specified in the class definition. In addition, classes have the following characteristics that make them especially useful for creating reusable, easily maintained code: All you need to know is that you can lift the receiver, dial the appropriate numbers, and talk to the person you want to talk to.
The complexity of making that connection is hidden. The benefit of being able to ignore the inner details of an object so you can focus on the aspects of the object you need to use is called abstraction. Internal complexity can be hidden. Encapsulation, which involves packaging method and property code together in an object, contributes to abstraction.
For example, the properties that determine the items in a list box and the code that executes when you choose an item in the list can be encapsulated in a single control that you add to a form. Leveraging the Power of Existing Classes A subclass can have all the functionality of an existing class, plus any additional controls or functionality you want to give it. If your class is a basic telephone, you can have subclasses that have all the functionality of the original telephone and any specialized features you want to give them.
Subclassing allows you to reuse code. Subclassing is one way to decrease the amount of code you have to write. Start with the definition of an object that is close to what you want, and customize it.
Streamlining Code Maintenance With inheritance, if you make a change to a class, that change is reflected in all subclasses based on the class. This automatic update saves you time and effort. For example, if a phone manufacturer wanted to change from dial to push-button style phones, it would save a lot of work to be able to make the change to the master schematic and have all previously manufactured phones based on that master schematic automatically inherit this new feature, rather than having to add the new feature to all the existing phones individually.
Inheritance makes maintaining your code easy. If you discover a bug in your class, instead of having to go to each subclass and change the code, you fix it once in the class and the change propagates throughout all subclasses of the class. The Visual FoxPro class hierarchy. Container and Control Classes. Container Classes Containers can contain other objects and allow access to the objects contained within them. For example, if you create a container class that consists of two list boxes and two command buttons, and then add an object based on this class to a form, each individual object can be manipulated at run time and design time.
You can easily change the positions of the list boxes or the captions of the command buttons. You can also add objects to the control at design time; for example, you can add labels to identify the list boxes. The following table lists what each container class can contain: Container Command button groups Container Control Custom Form sets Forms Grid columns Grids Option button groups Page frames Pages Project Toolbars Can contain Command buttons Any controls Any controls Any controls, page frame, container, custom Forms, toolbars Page frames, any controls, containers, custom Headers and any objects except form sets, forms, toolbars, timers, and other columns Grid columns Option buttons Pages Any controls, containers, custom Files, servers Any controls, page frame, container.
Control Classes Control classes are more completely encapsulated than container classes are, but can be less flexible for that reason. Control classes do not have an AddObject method. Matching the Class to the Task You want to be able to use classes in many different contexts.
Smart planning will enable you to most effectively decide what classes to design and what functionality to include in the class. Encapsulate Generic Functionality You can create a control class for generic functionality. For example, command buttons that allow a user to move the record pointer in a table, a button to close a form, and a help button, can all be saved as classes and added to forms any time you want the forms to have this functionality.
You can expose properties and methods on a class so that the user can integrate them into the particular data environment of a form or form set.
Provide a Consistent Application Look and Feel You can create form set, form, and control classes with a distinctive appearance so that all the components of your application have the same look. For example, you could add graphics and specific color patterns to a form class and use that as a template for all forms you create.
You could create a text box class with a distinctive appearance, such as a shadowed effect, and use this class throughout your application any time you want to add a text box. Deciding What Type of Class to Create Visual FoxPro allows you to create several different kinds of classes, each with its own characteristics.
All Visual FoxPro base classes recognize the following minimum set of events: Occurs when the object is released from memory. Occurs whenever an error occurs in event or method procedures of the class. All Visual FoxPro base classes have the following minimum set of properties: The base class it was derived from, such as Form, Commandbutton, Custom, and so on.
The class library the class is stored in. The class that the current class was derived from. For example, if you want the default names of controls you add to forms in your applications to automatically reflect your naming conventions, you can create classes based on the Visual FoxPro base classes to do this. You can create form classes with a customized look or behavior to serve as templates for all the forms you create.
You could also subclass the Visual FoxPro base classes to create controls with encapsulated functionality. Release You can add this new button to any form in your application. Customized command button added to a form.
You can add multiple controls into a single container class definition. Many of the classes in the Visual FoxPro sample class library fall into this category.
For example, the VCR class in Buttons. You can create methods and properties for your custom class using the Class Designer environment. For example, you could create a custom class named StrMethods and include a number of methods to manipulate character strings. You could add this class to a form with an edit box and call the methods as needed. If you had a method called WordCount, you could call it when needed: Value Non-visual classes like the custom control and the timer control have a visual representation only at design time in the Form Designer.
Set the picture property of the custom class to the. Creating Classes You can create new classes in the Class Designer and you can see how each object will appear to the user as you design it. The New Class dialog box lets you specify what to call the new class, the class to base the new class on, and the library to store it in. Creating a new class. Modifying a Class Definition Once you have created a class, you can modify it.
Changes made to a class affect all the subclasses and all the objects based on this class. You can add an enhancement to a class or fix a bug in the class, and all the subclasses and objects based on the class will inherit the change.
To modify a class in the Project Manager 1. Select the class you want to modify. Choose Modify. The Class Designer opens. Otherwise, Visual FoxPro will not be able to locate the class when needed. Subclassing a Class Definition You can create a subclass of a user-defined class in one of two ways. To create a subclass of a user-defined class 1. In the New Class dialog box, click the dialog button to the right of the Based On box. In the Open dialog box, choose the class you want to base the new class on.
For example, to base a new class, x, on parentclass in Mylibrary. Using the Class Designer When you specify what class your new class is based on and the library to store the class in, the Class Designer opens.
Class Designer. The Class Designer provides the same interface that the Form Designer does, allowing you to see and edit the properties of your class in the Properties window. Code editing windows allow you to write code to be executed when events occur or methods are called. Adding Objects to a Control or Container Class If you base the new class on the control or container class, you can add controls to it the same way you add controls in the Form Designer: No matter what type of class you base the new class on, you can set properties and write method code.
You can also create new properties and methods for the class. Adding Properties and Methods to a Class You can add as many new properties and methods to the new class as you want. Properties hold values; methods hold procedural code to be run when you call the method. Creating New Properties and Methods When you create new properties and methods for classes, the properties and methods are scoped to the class, not to individual components in the class. To add a new property to a class 1.
From the Class menu, choose New Property. In the New Property dialog box, type the name of the property. Specify the visibility: Public, Protected, or Hidden. A Public property can be accessed anywhere in your application. Protected and Hidden properties and methods are.
New Property dialog box. Choose Add. You can also include a description of the property that will be displayed at the bottom of the Properties window in the Class Designer and in the Form Designer when the control is added to a form. Troubleshooting When you add a property to a class that can be set by a user of the class, the user could enter an invalid setting for your property that could cause run-time errors. You need to explicitly document the valid settings for the property. If your property can be set to 0, 1, or 2, for example, say so in the Description box of the New Property dialog box.
You might also want to verify the value of the property in code that references it. To create an array property G In the Name box of the New Property dialog box, specify the name, size, and dimensions of the array. For example, to create an array property named myarray with ten rows and two columns, type the following in the Name box: The array property can be managed and redimensioned at run time.
To add a new method to a class 1. From the Class menu, choose New Method. In the New Method dialog box, type the name of the method. Select the Access check box to create an Access method, select the Assign check box to create an Assign method, or select both check boxes to create Access and Assign methods. The code in an Access method is executed when the value of a property is queried, typically by using the property in an object reference, storing the value of the property to a variable, or displaying the value of property with a question mark?
Protecting and Hiding Class Members Properties and methods in a class definition are Public by default: Properties and methods that you designate as Protected can be accessed only by other methods in the class definition or in subclasses of the class. Properties and methods designated as Hidden can be accessed only by other members in the class definition.
To ensure correct functioning in some classes, you need to prevent users from programmatically changing the properties or calling the method from outside the class. The following example illustrates using protected properties and methods in a class. The stopwatch class included in Samples. The stopwatch class in Samples. The Stopwatch class contains labels and a timer. This class also has three protected properties, nSec, nMin, and nHour, and one protected method, UpdateDisplay.
The other three custom methods in the class, Start, Stop, and Reset, are not protected. Tip Choose Class Info on the Class menu to see the visibility of all properties and methods of a class. The protected properties are used in internal calculations in the UpdateDisplay method and the Timer event. The UpdateDisplay method sets the captions of the labels to reflect the elapsed time.
Convert the numeric properties to Character type for display in the label captions. Set the label captions, retaining the leading 0 if the value of the numeric property is less than The following table lists the code in the tmrSWatch. Timer event: Comments Increment the nSec property every time the timer event fires: If nSec has reached 60, reset it to 0 and increment the nMin property.
If nMin has reached 60, reset it to 0 and increment the nHour property.
Call the UpdateDisplay method when the new property values are set. The stopwatch class has three methods that are not protected: Start, Stop, and Reset. A user can call these methods directly to control the stopwatch. The Start method contains the following line of code: The Stop method contains the following line of code: The Reset method sets the protected properties to zero and calls the protected method: UpdateDisplay The user cannot directly set these properties or call this method, but code in the Reset method can.
Specifying the Default Value for a Property When you create a new property, the default setting is false. To specify a different default setting for a property, use the Properties window. In the Other tab, click on your property and set it to the desired value. This will be the initial property setting when the class is added to a form or form set. You can also set any of the base class properties in the Class Designer.