Solved

Foxpro 2.6 browse

Posted on 2013-11-04
29
2,534 Views
Last Modified: 2013-11-30
Is it possible to create a browse using Foxpro 2.6.
One where you can search and select a record?
0
Comment
Question by:Idarac
  • 12
  • 10
  • 7
29 Comments
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39623370
You mean something like a grid and a search box? Of course.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39623374
This is a very simple form

Let's say you have store the search value in m.value

SELECT * FROM customer WHERE m.value $ name+telephone+address+city+country
BROWSE NORMAL
0
 
LVL 41

Expert Comment

by:pcelba
ID: 39623673
0
 
LVL 1

Author Comment

by:Idarac
ID: 39635701
Yes I am looking for the case where you say have a database of codes and you want to edit them.

You bring up a browse which shosw all codes allows you (search by typing in a code) then select the code bringing back the code record to the program
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39635716
Of course.

You use the BROWSE that is very native to FoxPro and you add code whereby when the user hits ENTER to open the Edit Window.

MODIFY MEMO WINDOW mywindow
mywindow is defined with DEFINE WINDOW

I am not sure about the code 100% since I have not coded in 2.6 since the 90s :).
0
 
LVL 41

Expert Comment

by:pcelba
ID: 39635863
BTW, the simplest search solution in a BROWSE window is  CTRL+F  hotkey. It displays a small window where you can enter the text to search... It searches all columns in the table.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39636225
The BROWSE is the best feature I have ever seen in the programming world. I use it almost on daily basis.
0
 
LVL 1

Author Comment

by:Idarac
ID: 39636921
I have the browse working but now I want to select a record press (any) key the browse disappears and it brings the record into a form for editing.
0
 
LVL 1

Author Comment

by:Idarac
ID: 39636931
Now I am not sure if it is the browse command I need. I want to bring up a list of records and be abel to select one and bring the fields into a coded form.
0
 
LVL 27

Accepted Solution

by:
CaptainCyril earned 250 total points
ID: 39636945
I don't remember how to trap any key in FoxPro 2.6.

I usually do

ON KEY LABEL F2 DO UserWishesToEditCode
BROWSE
ON KEY LABEL F2 && This is to disable to procedure call when BROWSE window is closed

PROCEDURE UserWishesToEditCode
ON KEY LABEL F2
MODIFY MEMO table.code

Open in new window

0
 
LVL 41

Assisted Solution

by:pcelba
pcelba earned 250 total points
ID: 39636963
F2 hotkey is OK but Idarac needs to edit the BROWSE record in a separate form so I would recommend this way:
PROCEDURE UserWishesToEditCode
ON KEY LABEL F2
RELEASE WINDOW YourBrowseWindow
DO YourEditScr.SPR

Open in new window

YourEditScr.SPR is a standard FoxPro edit window created in the Screen designer where GET fields are assigned to table fields or memory variables - depends on your programming standards.
0
 
LVL 1

Author Comment

by:Idarac
ID: 39637072
Is it possible to change the sort order on trhe browse.

I set an index but the records show in the order they were entered.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39637094
Do that by the query

SELECT * FROM .. WHERE ... ORDER BY title
BROWSE
0
 
LVL 1

Author Comment

by:Idarac
ID: 39637103
Thanks just a wokring away here...
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:Idarac
ID: 39637107
Any ideas on how to delete a record using a browse? I see you can mark for deletion but how would I get rid of it from the browse. Not show show records marked for deletion
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39637123
SET DELETED ON will hide records marked as DELETED.
You also need to refresh the window when you delete by GO TOP right after you delete.

So maybe create another keypress like F8 to do all that for you.
0
 
LVL 1

Author Comment

by:Idarac
ID: 39637201
With all your help I have cobbled together some code that actually works. Can you have a look and see if anything is wrong.

* set env to run application *
*
clear
clear all
set devi to scre
set talk off
set defa to project

* 1.Cread CDX index files if not exist
* 2.Build index if CDX files EXIST

if file("repcdx.cdx")
   use salesrep inde repcdx
   rein
else
   use salesrep    
   INDEX ON UPPER(SLSR) TAG SLSRNAME OF repcdx
endif
if file("catcdx.cdx")
   use category inde catcdx
   rein
else
   use category  
   INDEX ON UPPER(SS)+UPPER(CAT) TAG SSCAT OF catcdx
endif


close all

* Define and display main window

DEFINE WINDOW menter FROM 1,5 TO 24,60 DOUBLE
ACTIVATE WINDOW menter

* Loop untill user select EXIT option in main menu
wexit =.t.
do while wexit
   clear
   @3,12 say "CATEGORY"
   @5,12 prompt "1. Add Categoryz"
   @7,12 prompt "2. Edit Category"

   @9,12 say "SALESREP"
   @11,12 prompt "3. Add Sales Rep"
   @13,12 prompt "4. Edit Sales Rep"
   @16,12 prompt "5. Exit"
   menu to mmenu


   DO CASE
      CASE mmenu = 1  
         * Add Category
         do ADDTHECAT
      CASE mmenu = 2  
         * Edit Category
         do EDITTHECAT
      CASE mmenu = 3  
         * Add Rep
         *do addrep
      CASE mmenu = 4  
         * Edit Rep
         *do editrep
      OTHERWISE
            wexit = .f.
            clear
        clear all
        close all
        set devi to scre
        set talk on  
        set defa to
            quit
   ENDCASE  
endd


function CustFind
*****************
define window CustFind from 04,40 to 07,80 in window screen font 'arial',8 title 'Find..'
activate window CustFind
@ 0,0 get VarFind pict '@!' default space(40)
READ
release window CustFind
GO TOP
count while upper(CAT)#allt(upper(VarFind))
RETURN

Function EDITIT
******************
* Open database
*
*sele 1
*use CATEGORY index catcdx

* Initaliz all variable
*
clear
wss = space(1)
wsave = "Y"
wcat = space(3)
wcatdes = space(50)
wvalid = .t.
wmore = "Y"

*DEFINE WINDOW menter FROM 1,5 TO 24,60 DOUBLE
define window CustFind from 1,5 to 24,60 in window screen font 'arial',8 title 'Find..'
activate window CustFind
@1, 2 say "SSz          :"
@3, 2 say "CATq         :"
@5, 2 say "Description :"
@1,15 get SS pict "@!A"
@3,15 get CAT pict "@!A"
@5,15 get DESC pict "@!A"
READ
release window CustFind

RETURN

function CustDelete
*****************
wmore = "Y"
define window CustFind from 04,40 to 07,80 in window screen font 'arial',8 title 'Mark for Deletion..'
activate window CustFind
@1, 2 say "Delete        :"
@1,15 get wmore pict "@!A"
DELETE
release window CustFind
*GO TOP
RETURN

FUNCTION EDITTHECAT
*******************
wvalid = .t.
*use customer
use category inde catcdx
SET ORDER TO 1
SET DELETED ON
* This main loop will process untill user want to EXIT
*do while wvalid
  define window customer from 5,5 to 20,80 in window screen font 'arial',8 title 'Customer Database  F2=Search F5=Edit'
  move window customer center
  ON key labe F2 do CustFind
  ON key labe F5 do EDITIT
  ON key labe F6 do CustDelete
  browse FIELDS SS,CAT window customer noedit
  ON key labe F2
  release window customer
*endd
RETURN

FUNCTION ADDTHECAT
*******************
wvalid = .t.
*use customer
use category inde catcdx
SET ORDER TO 1
* This main loop will process untill user want to EXIT
*do while wvalid
  define window customer from 5,5 to 20,80 in window screen font 'arial',8 title 'Customer Database  F2=Search F5=Edit'
  move window customer center
  ON key labe F2 do EDITIT
  ON key labe F5
  ON key labe F6 do ADDIT
  browse FIELDS SS,CAT window customer noedit
  ON key labe F2
  release window customer
*endd
RETURN

FUNCTION ADDIT
******************
append blank
replace SS with "N"
        replace CAT with "OON"
        replace DESC with "FARNNN"
RETURN
0
 
LVL 1

Author Comment

by:Idarac
ID: 39637231
I am using this line to search and find a matching record.
count while upper(CAT)#allt(upper(VarFind))

What should I be using and can I find a partial match
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39637236
To locate a record

LOCATE FOR String $ UPPER(CAT)
0
 
LVL 41

Expert Comment

by:pcelba
ID: 39637258
COUNT WHILE starts at the current record (respecting the master index)
LOCATE FOR starts at the first record (respecting the master index)

To find the partial match from the beginning of the field you may use

SET EXACT OFF
LOCATE FOR UPPER(cat) = ALLTRIM(UPPER(VarFind))

Substring offered by Captain is also possible option.

BTW, are we talking about FoxPro/DOS  or  FoxPro for Windows here?
0
 
LVL 1

Author Comment

by:Idarac
ID: 39637608
OK hopefully the last dumb question then I will close it.

What is the difference between using Seek and Locate? Can I do partial matching with each?
0
 
LVL 41

Expert Comment

by:pcelba
ID: 39637632
Well... depends what you mean by partial matching. If you are looking for a substring then you cannot use SEEK. If you are looking for the beginning of the string in your field then you can use whatever you want and SET EXACT OFF or some other technique (e.g. SET NEAR) can allow partial matching.

SEEK needs index. Always. And SEEK is faster than LOCATE (always).
LOCATE does not need any index (and data are then searched row by row top to bottom) but LOCATE can utilize Rushmore to optimize the data access if appropriate indexes exist.
0
 
LVL 1

Author Comment

by:Idarac
ID: 39637759
I have one more what is the difference between the List and Browse?
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39637828
LIST is an object that shows rows but usually it is of one column and it is made for selection only. BROWSE displays many fields and is more versatile. You can do editing in it, play with the width of the columns, scroll horizontally, scroll within fields, etc., ...
0
 
LVL 41

Expert Comment

by:pcelba
ID: 39638126
Hmm... FoxPro 2.6 does not know the List object... I don't suppose you mean the @ ... GET... FROM  |  POPUP which simulates a popup list.

So LIST is a command which lists the current workarea table to the screen or to the active window. You can specify fields which are listed, you can redirect the output to a file or printer and that's almost all. You cannot update or even format the output.

BROWSE is interactive command which allows much more than the LIST command. OTOH BROWSE cannot redirect the output to a file or printer...
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39638165
LIST command prints to the SCREEN
I think he means ListBox and I forgot what it was called back in 2.6. I don't have 2.6 anymore on my 64-bit Vista :).
0
 
LVL 1

Assisted Solution

by:Idarac
Idarac earned 0 total points
ID: 39638855
What do you mean  

 @ ... GET... FROM  |  POPUP which simulates a popup list.

Is th is something you can do in the DOS version?
0
 
LVL 41

Expert Comment

by:pcelba
ID: 39638982
Of course, look at the @ ... GET command in help.

FoxPro 2.6/DOS supports standard menu (designed visually) and several special @ ... GET commands to create Check boxes, Radio buttons, Command buttons, Spinners, etc.

Everything is described in the Language part of the help file and these commands are also generated when you design the screen visually in the FoxPro Screen designer.
0
 
LVL 1

Author Closing Comment

by:Idarac
ID: 39686648
Thanx to you both on your answers. I just did not know how to award points on this one except to pick one answer from both and select multiple solutions. Just great answers from stat to finish and I am well on way to designing my program. I was forced to select only one for best solution I did that by coin toss.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now