Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hacker's Guide to VFP 7.0 said:This is an oldie-but-baddie command. Back in the days before indexes, it was an awfully important command, but it's been superseded so many times, we've lost count.
SORT makes a copy of a table, physically ordering the records in the new table according to specified criteria. SORT is a resource hog—it can require as much as three times the disk space occupied by the table to do the copying. Because you can do the same thing with COPY TO and an index, or SELECT-SQL, there's not much reason to use SORT.
Lower(), Proper(), Upper()
It's a funny thing. These three functions do very similar things, yet UPPER() and LOWER() are among the most important functions in FoxPro, while PROPER() is one of the most useless. All three take a character string and return a string with the case of the letters modified — UPPER() converts them all to uppercase, LOWER() makes them all lowercase, and PROPER() supposedly makes proper names out of them (with a capital letter at the beginning of each word).
Usage
cResult = LOWER( cString )
cResult = PROPER( cString )
cResult = UPPER( cString )
In many comparisons and searches, using either UPPER() or LOWER() is essential, so the operation is case-insensitive. You don't want to worry about whether the user has entered "Smith", "smith", "SMITH", or "sMiTH". So you apply UPPER() or LOWER() to both sides of the comparison or to both the search string and the target of the search. For example, if a user has filled in variables cLastName and cFirstName, you could search for a matching record like this:
LOCATE FOR UPPER(LastName) = UPPER(cLastName) AND ;
UPPER(FirstName) = UPPER(cFirstName)
The same logic applies when creating indexes based on character strings. If case is irrelevant (which is true more often than not), apply UPPER() to the data being indexed and then always be sure to SEEK using UPPER(the search string). For example, to re-create the company name index for TasTrade's Customer table, you use:
INDEX ON UPPER(Company_Name) TAG Company_Na
Then, to search for QUICK-Stop, you'd:
SET ORDER TO TAG Company_na
SEEK "QUICK-STOP"
To search for the company whose name is contained in m.cCompany, use:
SEEK UPPER(m.cCompany)
Actually, if m.cCompany comes from user input, you should probably trim it first to get rid of any leading or trailing blanks that might have crept in:
SEEK UPPER(ALLTRIM(m.cCompany))
You can use LOWER() exactly the same way as UPPER() in searches and comparisons. Just pick one or the other and always use it, so you know what to expect. Harking back to our mainframe days, we tend to use UPPER(), but LOWER() is more readable, the ergonomists tell us; we just haven't lowered ourselves to using LOWER() yet.
PROPER() is one of those great ideas that just didn't work out. Its purpose is to let folks enter names without worrying about capitalization. Then, you can come along later and apply PROPER() to fix it up. Unfortunately, names just aren't that simple. While PROPER() is great for run-of-the-mill names (like Granor or Roche), it falls apart when you hand it stuff like O'Hara or MacNeill.
Fundamentally, PROPER() is too simple-minded to do the job. It takes whatever you hand it and returns it with the first character of each word capitalized. If that's not appropriate, too bad.
Mandy_crw said:i tried set collate before but i dont know for some reasons it did not work
Clear
Set Collate To "MACHINE"
Create Cursor collationdemomachine (cText C(1))
Index on cText tag cText
Insert into collationdemomachine values ('ñ')
Insert into collationdemomachine values ('n')
Insert into collationdemomachine values ('N')
Locate
Browse name loMachine nowait
loMachine.left = 200
? 'In MACHINE collation...'
Scan
? 'Are ',cText, ' and n equal?', cText = 'n'
? 'Are ',cText, ' and ñ equal?', cText = 'ñ'
EndScan
Set Collate To "SPANISH"
Create Cursor collationdemospanish (cText C(1))
Index on cText tag cText
Insert into collationdemospanish values ('ñ')
Insert into collationdemospanish values ('n')
Insert into collationdemospanish values ('N')
Locate
Browse name loSpanish nowait
loSpanish.left = 400
? 'In SPANISH collation...'
Scan
? 'Are ',cText, ' and n equal?', cText = 'n'
? 'Are ',cText, ' and ñ equal?', cText = 'ñ'
EndScan
Chris said:Indeed SET COLLALION alone does not change something. It has to be set before you create a table or an index, which then uses the currently set collation. And later, when using the table, the collation is automatic, "baked into" the table. Which makes it something that needs a table redefinition.
myself said:Indeed SET COLLALION alone does not change something. It has to be set before you create a table or an index, which then uses the currently set collation
USE foxcode
? Recno() && 1, as expected
SET FILTER TO RECNO()>1
? Recno() && 1, likely not as you expect filter to work, because if you verify the effect of a filter by doing
BROWSE nowait
? Recno() && 2, now the filter has been applied the first time (and many more times for all the rows showing in the browse window)