Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need idea for sort
Message
From
01/03/2010 01:05:53
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01451160
Message ID:
01451700
Views:
31
Hugo,

thank you
INSERT INTO c_test (value) VALUES ('1.02.2')
INSERT INTO c_test (value) VALUES ('1.02.10')
INSERT INTO c_test (value) VALUES ('1.02.N')
INSERT INTO c_test (value) VALUES ('1.02.NR')
INSERT INTO c_test (value) VALUES ('1.02.N.R')
fails.
I think I do not need tho have any word that long.

Agnes

>Agnes,
>
>The problem I see with the idea of padding the words to get the correct order is that the string could become too large to use in the sort by, to minimize it you can count first what is the maximum number of words, something like this
>
>
>LOCAL laMax[1]
>CREATE CURSOR c_Test (PK int autoinc, value char(40))
>
>INSERT INTO c_test (value) VALUES ('1.1')
>INSERT INTO c_test (value) VALUES ('1.02')
>INSERT INTO c_test (value) VALUES ('10.1')
>INSERT INTO c_test (value) VALUES ('01.3')
>INSERT INTO c_test (value) VALUES ('1.02.N')
>INSERT INTO c_test (value) VALUES ('1.02.N.R')
>INSERT INTO c_test (value) VALUES ('1.10.R')
>INSERT INTO c_test (value) VALUES ('1.10.R.1')
>INSERT INTO c_test (value) VALUES ('20DP')
>INSERT INTO c_test (value) VALUES ('20')
>INSERT INTO c_test (value) VALUES ('1.02.R')
>
>SELECT MAX(GETWORDCOUNT(value, '.')) FROM c_Test INTO ARRAY laMax
>
>SELECT getorder(ALLTRIM(c_test.value), laMax[1]), c_test.* FROM c_test ORDER BY 1
>
>
>FUNCTION getOrder(tcValue, tnMaxWords)
>
>LOCAL lnWord, lnWords, lcValue
>
>lnWords = GETWORDCOUNT(tcValue, '.')
>lcValue = ''
>FOR lnWord = 1 TO tnMaxWords
>	IF lnWord <= lnWords
>		lcValue = lcValue + PADL(GETWORDNUM(tcValue, lnWord, '.'), 40, '0') + '.'
>	ELSE
>		lcValue = lcValue + REPLICATE('0', 40)
>	ENDIF
>NEXT lnWord
>
>RETURN lcValue
>
>
>Note that the code is using a word length of 40, which is the max length a single "word" can have, and in this simple sample you sent it will work, but if you have a combination of large words and small words, all the extra paddings will make the string huge and unsuitable for the order by clause.
>
>Which it makes me believe this is not the right answer :)
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Reply
Map
View

Click here to load this message in the networking platform