April 24, 200322 yr Hello All I would like to find a formula that would allow me to take a value list i.e. "Colors" and get random item from that value list and deliver it to a field. Can someone help me with this? Value list "Colors" RED Orange yellow green Blue Violet Returns the random of the above list. ( "yellow " for example) Value list field, "Colorfield" File - "NewFile" Please can someone show me a fool proof efficent way to set this up. I would have a lot of uses to do this with value lists. Thanks again harty
April 25, 200322 yr Hi, My first thoughts would be to do it with a calculation that return a random occurence from your value list : 6 values woud lead to : c_randomOccurence = Int(Random*5) +1 where 5 is your total occurence Occurence (ValuelistItem(Status(CurrentFileName, "color list") to return a random occurence from 0 to 5 from your value list : 0 for first occurence, 1 for second,.... Then, the basic calcs to return a given occurence are : c_return1stOccurence =MIDDLE( ValueListItems(Status(CurrentFileName, "your color value list",1,POSITION(ValueListItems(Status(CurrentFileName, "your color value list", "
April 25, 200322 yr Author Does anyone have a working example of extracting a random value from a value list ? I just can't seem to make the examples here work properly. Thanks
April 25, 200322 yr Hi, Here is a working implementation. Some FM Gurus here would certainly come with a cleaner solution, but that's what I've got, you Lazy Man (Please tell if you can't download it. I've got some prob with DropZip, but you should open the files with FM when unzipped, even if they don't look as FM files. ) And for those 3 quick guys that already downloaded it, note that I've already modified the random formula without the +1, as 0 can be used here for 1st occurence) random.fp5.zip
April 25, 200322 yr Hi There How About this: Middle(ValueListItems (dbname, valuelist), (Position(ValueListItems (dbname, valuelist), "
April 25, 200322 yr Hi Pete, It looks great....Did you tried it ? It always return the last occurence when I use it. Maybe I just got confused when changing the overall syntax to my European FM. Thanks.
April 25, 200322 yr No it doesn't work - sorry! I forgot I am continually getting different results. One will have to create another field. So, it could be: RandomField = Truncate((PatternCount((ValueListItems(dbname, valuelist)), "
April 25, 200322 yr Hi. You don't need two fields for this. See attached working model. RandomValue.zip
April 25, 200322 yr Hi Pete, Or : random (auto-enter calc) = Int(Random*Patterncount(ValueListItems(Status(CurrentFileName), "colorlist"), "
April 25, 200322 yr Ray, You don't need to do this, while I'm previewing my latest post . I even didn't see your attachment but I already know it's working like a charm
April 25, 200322 yr Hi Guys All looks great. Now, lets assume you always want the predefined color field to remain. Ok, thats easy. But now we want only one more field that provides the solution - and not via a script. As I see it both the script and the calculation fields require 2 parts (so that there is no multiple randomising happening). How about a 1 part solution?
April 26, 200322 yr Hi, Sorry Ray I don't get nor Pete request, nor your solution. What"s exactly the point here ? Pete, If the random calculation is set as an auto-enter unmodificable, why would you like the record to change ?
April 26, 200322 yr Peter was asking for a way to select a random entry from the value list which requires only a single field and is not dependent on a script. The revised file I posted uses an auto-entry calculation. Although I left the script in my example, it is only there to show that the revised formula can work by script as well as via auto-entry calc - but it would only be required if the values were to be revised (randomly) after the record is created.
April 26, 200322 yr Haahhh!! OK, got it afterwards when revisiting your sample and creating a new record. And you did it with one field only !! Ray, you know already what Vaughan would say
April 26, 200322 yr Hi Guys Excellent - although I am still busy pulling apart your calculation. But, yes it does exactly what I wanted. Thanks Ray Pete
April 26, 200322 yr Help Me And here I thought my FM skills were pretty good. I'm blown away! (Although I still quietly hope that interpreting someone elses work is not necessarily very easy) Ray, I cannot seem to unravel your excellent calculation - how did you create it? When you faced the question what was your first step? I want to gain more insight into the thought process that ultimately leads to such a result. Also, how long did it take you to work out? Pete
April 26, 200322 yr Hi Peter, The calculation is not as impenetrable as it first looks. You asked if the calculation could be achieved in one step. In the previous version a conventional parsing technique locates the start and stop characters using the Position function on the CRs. As you know, it is this procedure that depends on three succesive references to the random number. In considering other ways to parse the list - and being aware that the MiddleWords( ) function automatically breaks over CRS - I knew that if the value list were to contain only single word entries, it could be parsed using the MiddleWords( ) fucntion. The list in the demo *is* all single words, as it happens, but I knew that simply using MiddleWords( ) would cause the formula to break as soon as anyone decided to put a two-word item (eg 'dark blue') on the list - ie since MiddleWords( ) breaks over both spaces and CRs, this would be problematic. The solution was to eliminate the spaces (if any), replacing them with a string which is not likely to be found within any legitimate values, now or in the future, then apply the MiddleWords function to parse the list (now as 'single-word value packets'), and then subsequently reverse the substitution to put the spaces (if any) back in. A bit 'lateral', but feasible and not too onerous. So the logic of the formula, working from the middle out is: 1. Fetch the valuelist 2. Change the spaces to .spc. 3. generate random number n 4. take out the nth 'word' 5. Change the .spc. strings back to spaces With the result that single or multiple word value list items are parsed out accurately, yet the procedure depends on a single random number and can be compiled into a composite expression. For what it's worth that was the process. It took only a short time to write and test - perhaps about half of the time which elapsed between your query and my reply.
April 26, 200322 yr Author You guys are awesome. I have so much to go over with what you did. This is the best way for me to learn . Pull something apart and ask questions later. I especially liked hearing about the thought process. thanks so much all, It is great what happens here. thanks
April 26, 200322 yr Thanks Ray and thank you harty for starting an incredibly interesting, if not humbling, discussion. Pete
May 2, 200322 yr Hi to all! OK, Random looks fine. What if you need the exact selection from the list and not random? Is it possible?
May 2, 200322 yr What most people do when they want an exact selection from a value list, is to select it from a pop-up menu or checkbox field (etc). I am guessing, however, that what you are asking is whether extraction of a predetermined value from a list can be automated? It is difficult to think of many cases there you'd need to do this, because if you can predetermine which value is to be selected, then in most instances you won't need to extract it from the list, but can simply specify the value itself. Notwithstanding that, if you want the selection to be automated - but not random - then presumably you have in mind some method by which the 'exact' selection will be specified. Presumably it will be specified in either of two ways, you can say which value you want (in which case, as noted above, there is no longer a need to extract it from the list, because you can have a script enter it directly) - or you can spefify the number/position of the value to be selected. If you want to select a value from the list by number, then various ways to do that have already been discussed on this thread. The earlier examples suggested were all seeking to providing ways to get at a random list item in two steps, where the first step created a random number and the second step found the corresponding list item. It was only the last example that collapsed these two processes together. Using the approach exemplified in the final demo, you could retrieve the Nth value from a list with a formula along the lines of: Substitute(MiddleWords(Substitute(ValueListItems(Status(CurrentFileName), "Colors"), " ", ".spc."), N, 1), ".spc.", " ") ...where N is either a number (entered into the formula) or a field via which a variable number is to be supplied.
May 2, 200322 yr Well... The reason is so that i can do a "Find" for each of a few value lists selected (which in my case are conditional and can't do a find with) and so be extracted to a text box where as it can be searched. Its kind of a one way, what else could i do... Complicated huh?
May 2, 200322 yr Hi mastichis, I have a feeling the you are making things more complicated than they need to be. I suspect that a dynamic list selection system which is dependent upon mode might be preferable. An example of a set-up that provides this functionlality is attached. DynamicList.zip
May 2, 200322 yr For anyone following this thread, I have edited the formula cited in my 05/02/03 12:38 AM post (above) to correct a typographical issue (the sequence ") + 1" was included after N erroneously). For clarity, attached is a file which shows a working version of the corrected formula. ListExtract.zip
May 13, 200322 yr wouldn't it be easier to write a friendly little plug-in to extract a certain line, and to count the number of lines? instead of doing the arcane extraction in FM. I'm quite sure it is no more than about a page of C code, of which most would be decoding and coding numbers. . The actual productive code can't possibly be more than 15 lines of C. Getting a certain line, and counting the number of lines is so common it should be built-in. Peter
May 13, 200322 yr To Ray: your solution idea is very clever. Thanks. I did not find the definition of "word" in filemakers help, is there one? I found that multiple CR count practically as one separator, therefore it is even more safe to replace CR by .CR . and back.
May 13, 200322 yr I did not find the definition of "word" in filemakers help, is there one? Yes there is, after a fashion, but it doesn't appear in the help file. Instead, you'll need to pay a visit to the FMI TechInfo Knowledgebase to view it. Yhe URL is: http://www.filemaker.com/ti/103853.html And for added insight into how the different non-alphanumeric characters are interpreted by word related functions, it is also worth a visit to the related article: http://www.filemaker.com/ti/104103.html Once you have these in your 'kit' it's a lot easier to predict how FMP will behave when an XWords( ) function encounters a given string.
May 16, 200322 yr Ray thanks for the links. I consider bying a plug-in, or writing one, to break up lists, perhaps even doing DDE to a hypercard script. Do you know if there is a way to convert a repeating field into a value list (short of creating an item database file, one record per list item - and similar constructions) Peter
May 16, 200322 yr Hi Peter, Do you know if there is a way to convert a repeating field into a value list Yes. If you define a value list to use items from a repeating field, each repetition value will appear as a separate item on the list. If you define the list to be conditional, all the repetition values on any record that matches the condition will be listed.
May 17, 200322 yr Thanks. I did try. IMHO this handles the original question of this thread, too, with very little infrastructural design. I consider putting the repeating field and other DB parameters into the first record of the file, instead of into Admin, and make sure it does not get lost and seldom displayed. Maybe that's another thread in another subforum? Peter
Create an account or sign in to comment