Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Keeping an array sorted
Message
From
26/10/2000 15:37:43
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00434680
Message ID:
00434833
Views:
27
>>Depending exactly what you're doing, you could consider using a cursor rather than an array. You could then index it, and your sorting problems are over.
>>
>>Personally, I hardly ever use arrays, as cursors are more versatile and easier to work with.
>
>A cursor to hold 6 numbers seems like overkill. I also don't see how it would help. I wasn't trying to sort the numbers, I was trying to reorder them. I'd have the same problem with a cursor.
>
>Thanks,
>
>Michelle

You're right, in this case sorting won't obviously help you. However, a cursor still might make your life easier:
LOCAL ;
	lnLowestValue, ;
	lnLowestRow, ;
	lnNewValue

* Initialize the cursor:
CREATE CURSOR iTest ;
	(iValue I)

FOR lnIx = 1 TO 6 STEP 1
	INSERT INTO iTest ;
		(iValue) ;
		VALUES ;
			(lnIx)

ENDFOR

* Change the values:
lnLowestValue = 1
lnLowestRow = 3

REPLACE ALL ;
	iTest.iValue WITH IIF(RECNO("iTest") < lnLowestRow, ;
		RECNO("iTest") + (RECCOUNT("iTest") - lnLowestRow) + lnLowestValue, ;
		lnLowestValue + (RECNO("iTest") - lnLowestRow)) ;
	IN iTest
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform