Microsoft KB Archive/101046: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 71: | Line 71: | ||
PROCEDURE notcalled | PROCEDURE notcalled | ||
SELECT * FROM clients WHERE state= | SELECT * FROM clients WHERE state="CA" HAVING city="Los Angeles" | ||
</pre> | </pre> | ||
When the .EXE file is run, two expression boxes appear in succession. | When the .EXE file is run, two expression boxes appear in succession. | ||
Line 79: | Line 79: | ||
<div class="indent"> | <div class="indent"> | ||
<p><span class="kbd userinput"> = | <p><span class="kbd userinput"> ="TX"</span></p> | ||
</div></li> | </div></li> | ||
Line 86: | Line 86: | ||
<div class="indent"> | <div class="indent"> | ||
<p><span class="kbd userinput"> = | <p><span class="kbd userinput"> ="Lubbock"</span></p> | ||
</div></li></ol> | </div></li></ol> | ||
Line 101: | Line 101: | ||
DELETE FILE temp.dbf | DELETE FILE temp.dbf | ||
CREATE TABLE temp (City c(20),state c(2)) | CREATE TABLE temp (City c(20),state c(2)) | ||
INSERT INTO temp (city,state) VALUES ( | INSERT INTO temp (city,state) VALUES ("Charlotte","NC") | ||
INSERT INTO temp (city,state) VALUES ( | INSERT INTO temp (city,state) VALUES ("Seattle","WA") | ||
INSERT INTO temp (city,state) VALUES ( | INSERT INTO temp (city,state) VALUES ("Dallas","TX") | ||
INSERT INTO temp (city,state) VALUES ( | INSERT INTO temp (city,state) VALUES ("Atlanta","GA") | ||
x=INPUTBOX( | x=INPUTBOX("Enter city name" ) | ||
y=INPUTBOX( | y=INPUTBOX("Enter state") | ||
SELECT * FROM temp WHERE city=&x having state=&y INTO CURSOR test | SELECT * FROM temp WHERE city=&x having state=&y INTO CURSOR test | ||
Line 115: | Line 115: | ||
<li>Save the project and build an executable.</li> | <li>Save the project and build an executable.</li> | ||
<li>Run the executable created in Step 2.</li> | <li>Run the executable created in Step 2.</li> | ||
<li><p>Type this in the InputBox entitled | <li><p>Type this in the InputBox entitled "Enter city name" and press the OK button:<br /> | ||
<br /> | <br /> | ||
</p> | </p> | ||
<pre class="fixed_text"> | <pre class="fixed_text"> "Charlotte"</pre></li> | ||
<li><p>Type this in the InputBox entitled | <li><p>Type this in the InputBox entitled "Enter state" and press the OK button:"<br /> | ||
<br /> | <br /> | ||
</p> | </p> | ||
<pre class="fixed_text"> | <pre class="fixed_text"> "NC"</pre></li> | ||
<li>One record appears for Charlotte, NC. Press the close box of the form to exit the executable.</li></ol> | <li>One record appears for Charlotte, NC. Press the close box of the form to exit the executable.</li></ol> | ||
Line 131: | Line 131: | ||
== REFERENCES == | == REFERENCES == | ||
"Developer's Guide," version 2.0, page D16-11<br /> | |||
"Commands & Functions," version 2.0, page C3-10<br /> | |||
"Language Reference," version 2.5, page L3-9<br /> | |||
"Developer's Guide," version 2.5, page 14-11 | |||
</div> | </div> |
Revision as of 09:16, 20 July 2020
Article ID: 101046
Article Last Modified on 2/12/2007
APPLIES TO
- Microsoft FoxPro 2.0
- Microsoft FoxPro 2.5b for MS-DOS
- Microsoft FoxPro 2.5a
- Microsoft Visual FoxPro 3.0 Standard Edition
- Microsoft FoxPro 2.5b
- Microsoft FoxPro 2.5a
- Microsoft Visual FoxPro 7.0 Professional Edition
- Microsoft Visual FoxPro 8.0 Professional Edition
- Microsoft Visual FoxPro 9.0 Professional Edition
This article was previously published under Q101046
SUMMARY
A compiler cannot be accessed either in a stand-alone or compact executable file, so the Relational Query By Example (RQBE) screen is not available for the user to modify a query. However, the user can use macro substitution to modify a SELECT-SQL statement as needed within an executable file.
This technique will work in FoxPro for Windows with some modification. FoxPro for Windows does not create stand-alone executable files, but is capable of providing stand-alone applications. However, the query builder is not available in executable files built with the FoxPro for Windows Distribution Kit because it is intended to be used in interactive mode.
MORE INFORMATION
This code example below uses the Clients table found in the \Sample\Organize\dbfs folder of FoxPro 2.x. The code assumes the Clients table resides in the current folder. If you use this code with Visual FoxPro, then it is assumed that the Clients table from FoxPro 2.x was copied into the current folder.
The following program, which can be compiled into a stand-alone executable file, allows the user to dynamically change the SELECT-SQL statement as needed:
USE CLIENTS.DBF GETEXPR to x GETEXPR to y SELECT * FROM clients WHERE &x HAVING &y INTO CURSOR Test BROWS PROCEDURE notcalled SELECT * FROM clients WHERE state="CA" HAVING city="Los Angeles"
When the .EXE file is run, two expression boxes appear in succession.
- In the first, choose STATE from the Field Names box.
- Type the following, and choose OK.
="TX"
- In the next expression box, choose CITY from the Field Names box.
- Type the following, and choose OK.
="Lubbock"
This query will produce one record.
NOTE: Because macro substitution is used, the stand-alone executable file may not have the proper code included to perform the required function so an error may occur. To avoid this problem, the notcalled procedure includes code for a SELECT-SQL statement. When the executable file is compiled, FoxPro will include the necessary source code to execute the macro substitution. The notcalled procedure is not executed by the program.
In Visual FoxPro 7.0 and later versions, you can use the following code example.
Create a project, add a main program file, and add this code:
CLOSE ALL DELETE FILE temp.dbf CREATE TABLE temp (City c(20),state c(2)) INSERT INTO temp (city,state) VALUES ("Charlotte","NC") INSERT INTO temp (city,state) VALUES ("Seattle","WA") INSERT INTO temp (city,state) VALUES ("Dallas","TX") INSERT INTO temp (city,state) VALUES ("Atlanta","GA") x=INPUTBOX("Enter city name" ) y=INPUTBOX("Enter state") SELECT * FROM temp WHERE city=&x having state=&y INTO CURSOR test BROWSE CLOSE ALL DELETE FILE temp.dbf
- Save the project and build an executable.
- Run the executable created in Step 2.
Type this in the InputBox entitled "Enter city name" and press the OK button:
"Charlotte"
Type this in the InputBox entitled "Enter state" and press the OK button:"
"NC"
- One record appears for Charlotte, NC. Press the close box of the form to exit the executable.
REFERENCES
"Developer's Guide," version 2.0, page D16-11
"Commands & Functions," version 2.0, page C3-10
"Language Reference," version 2.5, page L3-9
"Developer's Guide," version 2.5, page 14-11
Additional query words: VFoxWin FoxDos FoxWin 2.x standalone memvar memory variable variables replaceable replacement
Keywords: kbcode KB101046