Re: returning result from a function when the number of items in the result varies
Thanks again. I'm going to fool with. Does an element in an array have a value? -- put [] is not empty -> "true" if it has a value, "false" if it does not So far the array is doing exactly what I wanted it to. And it is also saving me from trying to do something even more complex in SQL first. Valentina is really helping me to be lazy too as results from SQL calls to Valentina are so fast that I don't have to be very efficient. I'm using Valentina API methods and calling stuff all over the place. ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
On Sep 22, 2008, at 12:26 AM, Ken Ray wrote: Has an element in an array been defined yet? put is among the lines of (the keys of ) -> "true" if it has been defined, "false" if it has not been defined One additional note - as of Rev 2.9 you can also say: put is among the keys of http://www.screensteps.com Developer Resources: http://revolution.bluemangolearning.com ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
> So the number of lines in the KEYS of myArray is not a good test to see if > an array has data or even how many lines of data are in the array. True. Here's some basic tests (-> means "returns"): Is a Variable an Array? -- Rev 2.x: the keys of --> If empty, is not an array Rev 3.x: is an array --> "true" if it is, or "false" if it isn't What are the elements of an array? --- put the keys of -> return-delimited list of elements How many elements are in the array? - put the number of lines of (the keys of ) -> the number of elements Does an element in an array have a value? -- put [] is not empty -> "true" if it has a value, "false" if it does not Has an element in an array been defined yet? put is among the lines of (the keys of ) -> "true" if it has been defined, "false" if it has not been defined HTH, Ken Ray Sons of Thunder Software, Inc. Email: [EMAIL PROTECTED] Web Site: http://www.sonsothunder.com/ ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
Thanks again. I've got it now. I've noticed that the put number of lines in the keys of myarray -- returns a number that is the same whether or not an element in the array contains data. So the number of lines in the KEYS of myArray is not a good test to see if an array has data or even how many lines of data are in the array. So that taught me that it isn't a list. The only way I can test the array to see if a line contains data is to be disassembled first. I think that limits the use of the Array for some simpler functions as Jim Ault pointed out earlier. ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
The results in examples 1 and 2 were incorrect. put myArray [1] & return into toadMeatList put myArray [2] & return after toadMeatList put myArray [5] after toadMeatList RESULTS--> Jefferson Washington Elvis or in a "regular" loop put "1,2,5" into orderList repeat with n = 1 to numLines put myArray[n] & return after toadMeatList end repeat RESULTS--> Jefferson Washington Elvis It's not a list! It's an array. It's not THE NUMBER OF LINES in myArray. it's the number of lines in the KEYS of myArray. Big difference. I'll build a silly array here: ___ -- stephen barncard s a n f r a n c i s c o - - - - - - - - - - - - ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
It's not a list! It's an array. It's not THE NUMBER OF LINES in myArray. it's the number of lines in the KEYS of myArray. Big difference. I'll build a silly array here: set the itemdelimiter to comma put "Jefferson,Washington,Lincoln,Bush,Elvis" into historyList repeat with n = 1 to number of items in historyList put item n of historyList into myArray[n] end repeat Same as : 1) put the keys of myarray into tKeys 2) put number of lines in temp into tArrayLines Once again, you can't directly put an array into a field to "see" the elements. It needs to be 'disassembled', element by element This is expected behavior. You make a list by rotating through each key, either manually put myArray [1] & return into toadMeatList put myArray [2] & return after toadMeatList put myArray [5] after toadMeatList RESULTS--> 1Jefferson 2 Washington 5 Elvis or in a "regular" loop put "1,2,5" into orderList repeat with n = 1 to numLines put myArray[n] & return after toadMeatList end repeat RESULTS--> 1Jefferson 2 Washington 5 Elvis or using combine combine myArray with return & tab RESULTS--> 1Jefferson 2Washington 3Lincoln 4Bush 5Elvis From: "william humphrey" <[EMAIL PROTECTED]> To: "How to use Revolution" Subject: Re: returning result from a function when the number of items in the result varies Thanks again. I'm still curious about the array. When I use the "number of lines in myArray" I get the correct answer "1" before I send it out of the function as "myArray" but when I do the same "number of lines in myArray" after it is called then the answer is "0". If I ask for one key in the array (as myArray[1] ) and return that it works as expected. I understand that the contents of the array are invisible until I ask for one of the keys. But it still wasn't working as expected. I think Jim's suggestion might be better as the list of data elements can be handed back and it will work as I expect. It was fun to play with the array and I'm surprised that it doesn't return in the function like a list would as in my mind I think of the array as a list. -- stephen barncard s a n f r a n c i s c o - - - - - - - - - - - - ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
My mistake. Please ignore last post. Brain works better in morning. The array is returning correctly. I was just testing the results wrong. It looks like this is going to work and I think that it is much better to use the array as the key is generated by the data identifier and will thus be exactly what I need after it is returned. ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
Thanks again. I'm still curious about the array. When I use the "number of lines in myArray" I get the correct answer "1" before I send it out of the function as "myArray" but when I do the same "number of lines in myArray" after it is called then the answer is "0". If I ask for one key in the array (as myArray[1] ) and return that it works as expected. I understand that the contents of the array are invisible until I ask for one of the keys. But it still wasn't working as expected. I think Jim's suggestion might be better as the list of data elements can be handed back and it will work as I expect. It was fun to play with the array and I'm surprised that it doesn't return in the function like a list would as in my mind I think of the array as a list. ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
If there is no real reason to use an array in the function, then I would avoid it since your function may generate two 'hits' that happen to have the same key. In that case, only one answer will be returned since keys have to be unique. If you are transferring simple data, why not use the standard format of put empty into rtnString repeat for each --your code here put dataElement & tab & identifier & cr after rtnString end repeat filter rtnString without empty if rtnString is empty then put "no data -- no identifier" into rtnString return rtnString then in the main handler you have a list that will be something like dataElement identifier dataElement identifier dataElement identifier and dataElements can have the same value without data loss. Don't get me wrong, I use arrays every day, but the simple solutions seems to be more appropriate here. Hope this helps Jim Ault Las Vegas On 9/20/08 7:20 PM, "william humphrey" <[EMAIL PROTECTED]> wrote: > for some reason in my function if I say > > return myArray then I get an array with zero lines even when that is not > true. > > > If I say return myArray[1] (where 1 is one of the keys which has data in > the array) then it does return that correctly but just with that one line of > course. > > > This is why I hate arrays. It is not working like I expected. > > On 9/20/08, william humphrey <[EMAIL PROTECTED]> wrote: >> >> Thanks for not only answering but giving me the example. The repeat for >> each line in the array will work perfectly. > > > ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
william humphrey wrote: for some reason in my function if I say return myArray then I get an array with zero lines even when that is not true. If I say return myArray[1] (where 1 is one of the keys which has data in the array) then it does return that correctly but just with that one line of course. This is why I hate arrays. It is not working like I expected. Then maybe just consider a simple delimited list instead. Arrays are way cool for a great many things, but they're not the answer to every problem. Your data set is small enough that the specific operations that arrays excel at will have no noticeable performance difference doing them with a simple list. Extra bonus points for lists in your case: you can simply put the variable into a field, without having to run it through the combine command first. For small data sets performance won't matter much either way. But for large collections of things, the split and combine commands are very computationally expensive. Because they're effectively parsing and delimiting the data entire set, they're really only doing what you can do yourself with "repeat for each" but without the extra step. For random access of specific elements, the efficient internal hashed representation of keys makes accessing array elements several orders of magnitude faster than any method for finding lines in a list. But if you're not doing frequent random access the tradeoffs become the sort of thing where there is no best answer, it really depends on what you're doing. In your case your data set is small, so you have the luxury of doing whatever feels most comfortable. Have fun! -- Richard Gaskin Managing Editor, revJournal ___ Rev tips, tutorials and more: http://www.revJournal.com ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
HEY! that's not fair to the arrays. :) They REALLY are useful and amazing. Honestly, once you have you're aha moment you'll understand it. Your code is working as expected. For now, Just imagine the array to be a package of little ordinary variables that can be easily manipulated. put array into fld "output"-- won't be seen You can't "see" an array when "put" it - it's still there but you can't put it into anything except another array (or save it as a custom property) put array into array2 set the customproperty[myarray] of this stack to array If you want to see the elements you gotta take it apart. combine does that. combine with return and tab which turns the array into a single text string or the repeat for each line tKey in the keys of array put tKey & return after tOut end repeat put tOut for some reason in my function if I say return myArray then I get an array with zero lines even when that is not true. If I say return myArray[1] (where 1 is one of the keys which has data in the array) then it does return that correctly but just with that one line of course. This is why I hate arrays. It is not working like I expected. On 9/20/08, william humphrey <[EMAIL PROTECTED]> wrote: Thanks for not only answering but giving me the example. The repeat for > each line in the array will work perfectly. -- stephen barncard s a n f r a n c i s c o - - - - - - - - - - - - ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
for some reason in my function if I say return myArray then I get an array with zero lines even when that is not true. If I say return myArray[1] (where 1 is one of the keys which has data in the array) then it does return that correctly but just with that one line of course. This is why I hate arrays. It is not working like I expected. On 9/20/08, william humphrey <[EMAIL PROTECTED]> wrote: > > Thanks for not only answering but giving me the example. The repeat for > each line in the array will work perfectly. -- http://www.bluewatermaritime.com ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
Thanks for not only answering but giving me the example. The repeat for each line in the array will work perfectly. ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
You've practically designed it! Arrays are your friend. { below not tested} function yourFunction arrayVar put Timestamp & tab & "FDSFSDF" into myArray[garbage] put "toad" into myArray[green] return myArray end yourFunction put yourFunction() into Array combine array with return and tab put Array --> garbage20080923FDSFSDF greentoad To get the number of elements in an array: number of lines in myArray even better ( I love this one - think binary): repeat for each line tKey in the keys of tArray put tArray[tKey] & return after tArrayContents end repeat to sort: put the keys of myArray into myVariable sort lines of myVariable I'm having trouble sorting this out. I have a function that searches through lines of tab delimited text. The number of lines varies from one to ten. The result from the search is two things. A data element and a pointer that says which kind of data element. Sometimes the result is one data element and one pointer and sometimes the result is another quantity like three data elements each with their identifier. To have this returned by the function it seems I need an array. I'm inexperienced at using arrays but I imagine that you just build it in the function and that is what is returned and then the identifiers for each data element are the keys and it makes no difference how many lines are in the array? Perhaps I also return a counter which says how many lines of data are in the array? -- stephen barncard s a n f r a n c i s c o - - - - - - - - - - - - ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
William, you've got the idea. Arrays are really useful in these circumstances, and are really worth becoming familiar with. Best, Mark On 21 Sep 2008, at 01:13, william humphrey wrote: I'm having trouble sorting this out. I have a function that searches through lines of tab delimited text. The number of lines varies from one to ten. The result from the search is two things. A data element and a pointer that says which kind of data element. Sometimes the result is one data element and one pointer and sometimes the result is another quantity like three data elements each with their identifier. To have this returned by the function it seems I need an array. I'm inexperienced at using arrays but I imagine that you just build it in the function and that is what is returned and then the identifiers for each data element are the keys and it makes no difference how many lines are in the array? Perhaps I also return a counter which says how many lines of data are in the array? ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: returning result from a function when the number of items in the result varies
William, When I needed to do something like this in HC, I'd build a string consisting of several comma delimited words/values and return that string. Then I'd evaluate the string for what I needed. That should work in Rev as well. It's kind of like using an array, I suppose. (smile) HTH Joe Wilkins On Sep 20, 2008, at 5:13 PM, william humphrey wrote: I'm having trouble sorting this out. I have a function that searches through lines of tab delimited text. The number of lines varies from one to ten. The result from the search is two things. A data element and a pointer that says which kind of data element. Sometimes the result is one data element and one pointer and sometimes the result is another quantity like three data elements each with their identifier. To have this returned by the function it seems I need an array. I'm inexperienced at using arrays but I imagine that you just build it in the function and that is what is returned and then the identifiers for each data element are the keys and it makes no difference how many lines are in the array? Perhaps I also return a counter which says how many lines of data are in the array? _ ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
returning result from a function when the number of items in the result varies
I'm having trouble sorting this out. I have a function that searches through lines of tab delimited text. The number of lines varies from one to ten. The result from the search is two things. A data element and a pointer that says which kind of data element. Sometimes the result is one data element and one pointer and sometimes the result is another quantity like three data elements each with their identifier. To have this returned by the function it seems I need an array. I'm inexperienced at using arrays but I imagine that you just build it in the function and that is what is returned and then the identifiers for each data element are the keys and it makes no difference how many lines are in the array? Perhaps I also return a counter which says how many lines of data are in the array? ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution