Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I allot prizes to a person on different dates?

Status
Not open for further replies.

janak vyas

Technical User
Jun 3, 2020
47
IN
WhatsApp_Image_2020-07-11_at_6.55.39_PM_zsmxau.jpg



I tried using Rand() but I am failing in implementing something like this, where I randomly give the employees prizes on random dates while also having control and constraining the number of prizes an employee can get.
I have only used and seen/understand old foxpro codes so I will appreciate If any one can help with writing a function for this. Please.

( I have attached a picture just if I am not able to explain my question )
 
Mike, I fear I can't help you reproduce the error, but just calling FILED(0) or such doesn'T error, it's the use of an empty string as a field name that causes the final syntax error, I don't know why that would differ under any circumstance. REPLACE (field(200)) WITH 42. Nothing?

Do you have an error handler on, suppressing or just silently logging errors?

Jamak,

the usual practice to get an exact amount of different random numbers is not going with other generators, you can't adjust the behaviour to get next N numbers not overlapping.
As you have lots of empty cells at the end I'd rather turn the for loop counter back 1 and repeat the loop once more, whenever field(X) already has its 'W' allotted, so check that before the REPLACE.

The simplest always working solution that will be better in cases you would want to pick 100% of all items just in random order is to use the random number to pick one item of a list of not already picked items and reduce that list during the process. So no item can be fetched twice or no day allotted twice. That also means your number range will get 1 shorter every time.

That's taking a little bit more effort in VFP. Using a cursor and DELETE rows you're faced with the deletion marking. RECCOUNT() won't drop by 1, the RECNO() you delete only will get a deleted() status. So you'd need to use other mechanisms like a collection or array you can really reduce. But it's overkill for your case, just repeat until you have hit enough empty cells.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Do you have an error handler on, suppressing or just silently logging errors
?

No. I was just running these tests in the command window, with no other code active. But it's not important. I see that he has got past the syntax error now.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top