Using ACCEPT or INPUT
Some items won't convert directly using the Component Builder. For example, the commands "ACCEPT" or "INPUT" will not work in dBASE Plus. If you were to leave them in your programs, they would not look ,or act, like a Windows application.
Suppose you wanted to use code to find a person in an address book, and view or edit their data. You would use code similar to:
public cSearch && make it public so that the search form can find
&& it in memory
use address order name
do while .t. && loop until told to exit
cSearch = space(15) && initialize it
accept "Last Name to find: " to cSearch
*-- when the form is closed, the memvar will either
*-- have a name, or it will be empty ...
if isblank(cSearch)
exit
endif
*-- if here, we have a value, let's try to find it!
lOK = .f. && initialize flag
if seek(upper(trim(cSearch))) && if we found a match
do while trim(upper(cSearch)) $ trim(upper(last))
accept trim(first)+" "+trim(last)+;
" -- is this the name [Y/N]? " to cYN
if upper(left(cYN,1)) = "Y" && found a match
lOK = .t.
exit
else
lOK = .f.
skip
endif
enddo
else && match not found
lOK = .f.
endif
if .not. lOK && we didn't find it, let user know
?
? "*** No match found ***"
?
else && we DID find it, display the form
do address.fmt
endif
enddo
use
This code could to be modified so:
the ACCEPT command was not used
the code displays the address form, not the old DOS .FMT file.
To start with, you want a form that prompts the user for the name of the person in the address book.
Click on the "Forms" icon in the Navigator, and double-click on the first "Untitled" icon on the right side. This will bring up a new form in the designer.
Drag a text control from the Control Palette to the design surface, and place it toward the top of the form.
Widen it by dragging the right edge to the right.
Click the Inspector, and in the text property field, type: "Last Name to find:".
Adjust the size of the text by changing the fontSize property to a larger value, such as 10 or 12 (You may need to readjust the Text object’s height and width properties as well).
Drag an Entryfield object next to the text object.
Widen it , and set the fontSize to the same size used for the Text object.
Adjust the height and width as needed.
Move it so it aligns the way you want.
Set the dataLink property to "cSearch" (type that in the Inspector without the quotes).
Click on the Form.
In the Inspector change the form's mdi property to F.
Set the form's autoCenter property to T to center the Form
Press Ctrl+S to save. Name the file "search".
You now have a pushbutton the user will click to perform the search. Click on the "Component Palette", select the "Custom Tab", drag the "Closebutton" to the form, and center it under the controls. Resize the form, and it's done.
Modify the above code by replacing the "ACCEPT" command line with:
do search.wfm with .t.
This line will run the form, and the "with .t." ensures it runs as a modal form.
The section,
accept trim(first)+" "+trim(last)+;
" -- is this the name [Y/N]? " to cYN
if upper(left(cYN,1)) = "Y" && found a match
can be changed to use a built-in Visual dBASE dialog box that prompts for yes/no answers. This is called a Message Box, and it's called using the msgbox( ) function.
Change both of these lines to:
if msgbox( trim(first)+" "+trim(last)+;
" -- is this the name?", "Confirm", 4 ) = 6
If a match is found, this will prompt the user to confirm that the find was correct using "Yes" and "No" buttons.
To replace the code displaying a message that no match was found,
?
? "*** No match found ***"
?
call the msgbox( ) function once again:
msgbox("We did not find it.","No Match Found")
This displays only the message, and an "OK" button.
Replace the code that calls the screen (.FMT file),
do address.fmt
with
do address.wfm with .t.