arekowczarek Posted November 6, 2010 Report Share Posted November 6, 2010 I have a macro that at one stage contains 200 loops, each contained within the others. The farther into the loop I get, the farther the indent in the script gets. So, to see what's in the very middle of all the loops, I have to disable the previous, let's say, 180 Repeat Start commands. It's seen better on the screenshot I attached. Is there any way to help it? I know a horizontal slider would do the job, why it's not there is a mystery to me. Or mayby it's not there only on my PC? (ME PRO 4.2.1.1 running on Win XP PRO) Any other ideas of expanding the script editor window so I can see all the lines in full length without disabling previous commands? KOMBINACJA K=200.mex Quote Link to comment Share on other sites More sharing options...
paul Posted November 7, 2010 Report Share Posted November 7, 2010 How could anyone (including you) ever successfully debug this script? If you are able, using simple English, to describe in detail what this macro is supposed to do, I imagine there would be a better way of achieving your goal. In fact, I seriously doubt if any of us could find a worse way! Quote Link to comment Share on other sites More sharing options...
arekowczarek Posted November 7, 2010 Author Report Share Posted November 7, 2010 How could anyone (including you) ever successfully debug this script? If you are able, using simple English, to describe in detail what this macro is supposed to do, I imagine there would be a better way of achieving your goal. In fact, I seriously doubt if any of us could find a worse way! Imagine 40 lines of pixels, each 200 pixel long. What the macro does is try to find a combination of pixels at certain positions in the line, to find the smallest number of pixels that will distinguish each single line from the other ones. See the picture attached now. However, it have 200 macros to do it. Macro KOMBINACJA K=200 finds a combination of 200 pixels within 201 pixel long lines. Macro KOMBINACJA K=199 finds a combination of 199 pixels within 200 pixel long lines. ... ... ... ... Macro KOMBINACJA K=2 finds a combination of 2 pixels within 3 pixel long lines. Of course if, let's say the macro KOMBINACJA K=18 doesn't come up with a unique combination, the whole operation stops and I am given 19 pixel long combination. (it returns the position in the horizontal line of every one of the 19 pixels) You'll now ask: Why not create ONE macro (instead of 200) that will look for let's say 20 pixels within those 200 pixel long lines, that will distinguish all of them from the others? Oh, I’m glad you asked Let's see... N=200, K=20 The total count of 20-element combinations within 200-element set is: 1613587787967350073386147640 combinations! Well, it's not that bad, it'd take roughly 407 years 3 months and 6 hrs (provided that Windows doesn't crash in the meantime) to check all the combinations. However, it'd still not guarantee a successful result - cause there might not be 20 pixels that will distinguish all the lines. Then I'd need to check for N=200, K=21 ….and so on until a result is found Now, just to compare, how long it takes to find the *shortest* unique combination of pixels for my macro? About 2 minutes. (TWO MINUTES) (please take a moment to allow this information sink in) Now, the "shortest" is a little tricky here, cause when my macro finds i.e. 18 long pixel combination, there's a chance that there exists an i.e 14 pixel combination. But those literally few pixels don't matter if you consider the time the calculation took (several hundred years vs 2 minutes) As for the loop itself: What the loop does is to calculate every possible combination within a set of numbers. So, I'll explain it on the macro KOMBINACJA K=4 example. (it should return all 4-element combinations within 5-element set) The repeat loop is supposed to provide those following combinations of numbers: 1 2 3 4 1 2 3 5 1 2 4 5 1 3 4 5 2 3 4 5 Now that was easy. The repeat loop was just few lines long. One Repeat command is responsible for calculation of one number. Now, I didn’t see any other way (I truly believe if it exists it’s gotta be way way slower) to increase the count of numbers calculated without just applying further Repeat commands. Each number has to be calculated separetly, depending on all other numbers calculated, that's a fact. If you think it is possible to make a macro that will provide all combination within certain set of numbers, without an enormous number of loops contained within each other, I'd love to know how. I want to make clear that at one cycle, the "whole repeat loop" provides one unique combination that wasn't already calculated before. If the numbers were calculated without the consideration of the other numbers, it would lead (and I can confirm IT DID) to a situation when certain combination are calculated more than once. Here's an example: 1 2 3 4 4 1 2 3 3 4 1 2 2 3 4 1 Those four above combinations are all the SAME. One of them is enough, no need to check 2341 if 1234 was already checked. That's why all the repeat start/end commands are contained within each other, to eliminate unnecessary calculations and save time. As for the debugging - it wasn't necessary. What I did is: I debugged the KOMBINACJA K=3 macro. Then I created KOMBINACJA K=4 macro using a key (those macros are very linear). Debugged it too. Then I just wrote a macro that created macros from KOMBINACJA 4 to KOMBINACJA 200 using the differential key (not sure if that's the right phrase but it sounds so smart I can't stop myself from using it). Now, that's quite an essay I wrote here. I tried to explain it as clear as possible. Maybe someone will need just what I wrote, in this case I can surely provide the whole macro set. And I still need a solution for the question in topic. KOMBINACJA K=4.mex KOMBINACJA K=200.mex Quote Link to comment Share on other sites More sharing options...
paul Posted November 7, 2010 Report Share Posted November 7, 2010 If you think it is possible to make a macro that will provide all combination within certain set of numbers, without an enormous number of loops contained within each other, I'd love to know how. I want to make clear that at one cycle, the "whole repeat loop" provides one unique combination that wasn't already calculated before. If the numbers were calculated without the consideration of the other numbers, it would lead (and I can confirm IT DID) to a situation when certain combination are calculated more than once. Here's an example: 1 2 3 4 2 3 4 1 3 4 5 2 4 5 1 3 Those four above combinations are all the SAME. One of them is enough, no need to check 2341 if 1234 was already checked. That's why all the repeat start/end commands are contained within each other, to eliminate unnecessary calculations and save time. Thanks for providing your detailed and very interesting description. I don't follow here. How are the 3rd (3 4 5 2) and 4th (4 5 1 3) lines the same as any of the others? I can see that lines 1 and 2 contain the same numbers, whereas lines 3 and 4 are both unique. What am I missing? And I don't understand the output. WHat are the 6 pixels in each line formed from? Quote Link to comment Share on other sites More sharing options...
arekowczarek Posted November 7, 2010 Author Report Share Posted November 7, 2010 Thanks for providing your detailed and very interesting description. I don't follow here. How are the 3rd (3 4 5 2) and 4th (4 5 1 3) lines the same as any of the others? I can see that lines 1 and 2 contain the same numbers, whereas lines 3 and 4 are both unique. What am I missing? That was just a typo, it's correct now. And I don't understand the output. WHat are the 6 pixels in each line formed from? The 6 pixels (in the case shown in the picture) are pixels at the following positions: 32, 72, 131, 146, 184, 195. Macro copies the values at each of those numbers from each line of pixels, one [line] after another, and puts them together as a string. If it finds different values for each of the 40 lines, it moves on to the next macro. So, for the 1st line let it be: (the picture is too blurry so let's just assume) 100100 second... 011001 and so on up to the 40th line. The macros job was to find those pixels that will form the shortest possible set of 40 unique lines of pixels. The reason it stopped at 6 pixels would be there was no unique combination of 5 pixels. So the whole output might look like this: 100100 LINE 1 011001 LINE 2 011011 LINE 3 111001 LINE 4 010001 LINE 5 ... ... ... 100001 LINE 40 So now, if I want to find out which line of pixels is displayed I just read the 6 pixels at the positions mentioned above and if the pixels are i.e. 111001 (where white=0, black=1) and I know that LINE 4 is displayed. Because only LINE 4 would have this particular set of pixels (111001) at the mentioned positions. Hope it's clearer now P.S. And of course the macro input is not restricted to the use of 2 colours (black na white). I explained it in two colours cause it's the easiest way to see tha idea. It'll work same way for 3,5,10,100 or more different colours, where each colour has to have a different character assign to it. (however with a 100 different colors I could pick 5 random pixel positions and they'd probably all create different 5-pixel lines) Quote Link to comment Share on other sites More sharing options...
paul Posted November 7, 2010 Report Share Posted November 7, 2010 Does this work as a concept (don't let's worry about the implementation at this stage)? - Create an array of n rows by 200 integer columns (where n is the number of rows you will process). - Populate the array with the pixel values - Sort the array - Eliminate duplicates (do you need to remember eliminated line numbers?) - Process the array to determine the smallest number of elements that render each line unique - Create output Is this useful? Quote Link to comment Share on other sites More sharing options...
arekowczarek Posted November 8, 2010 Author Report Share Posted November 8, 2010 Does this work as a concept (don't let's worry about the implementation at this stage)? - Create an array of n rows by 200 integer columns (where n is the number of rows you will process). - Yes, however the array is stored as a string variable - Populate the array with the pixel values - Well, yes, accordingly to a colour, one single character representing a colour - Sort the array - I do it in a specially prepared MS Excel sheet, I just find if easier (takes up to 3 minutes). - Eliminate duplicates (do you need to remember eliminated line numbers?) The numbers of coloumns are dynamically assigned, I don't have to do any calculation myself. - Process the array to determine the smallest number of elements that render each line unique - Yes. - Create output - Yes. Is this useful? - Hell yes. See Picture 2 for a detailed step-by-step guide of processing 5 lines of pixels, each being 9 pixel long. See Use example for one of possible uses. Quote Link to comment Share on other sites More sharing options...
paul Posted November 8, 2010 Report Share Posted November 8, 2010 Ah, a mah-jong player perhaps? Are you any good? - Create an array of n rows by 200 integer columns (where n is the number of rows you will process).- Yes, however the array is stored as a string variable Suppose a 2-row array of these values: 100 1000 21 8810 A numeric array will correctly sort these rows as 21 8810 100 1000 while a string array will produce the opposite. Mind you, using Macro Express you can force all pixel values to be zero-filled to the left and 8-characters long, in which case strings will work fine. For an outstanding sort utility, take a look at this: RpSort (FYI I came across this utility in the early 1990s, and corresponded briefly with the author. A little while later the utility was published in a slightly different way - in fact, by his brother after the author's sudden and very untimely death.) Is this useful?- Hell yes. Does this mean you have sufficient information now to resolve your problem? Quote Link to comment Share on other sites More sharing options...
arekowczarek Posted November 8, 2010 Author Report Share Posted November 8, 2010 Ah, a mah-jong player perhaps? Are you any good? Well, having a macro that dynamically points out which tiles are matching I have to admit: Yes, I am good. That was just to test the combination macro abilities. Mah-jong fits the macro profile perfectly. Suppose a 2-row array of these values: 100 1000 21 8810 A numeric array will correctly sort these rows as 21 8810 100 1000 while a string array will produce the opposite. No such thing takes place. Each colour is represented by single character in a text string. If the input pixel line length is 200, then first 200 characters represent values of pixels in first line, next 200 characters represent values of pixels in the second line and so on. And yes, I know I could store real pixel colors with the use of padding, but then again - what for? It's way easier to compare visually pixels in the representation colour form. For comparison: 16777215 represented by 0 -white 0 represented by 1-black 255 represented by 3-red 5 pixel line: REPRESENTATION COLOURS 103113 REAL COLOUR VALUES _______016777215_____255_______0_______0_____255 (had to use understikes instead of spaces here) To me there's no doubt the representation colour way is a lot easier to read. Does this mean you have sufficient information now to resolve your problem? I was referring to the macro usefulness itself, I don't see how this would resolve the problem mentioned in the topic. Quote Link to comment Share on other sites More sharing options...
paul Posted November 8, 2010 Report Share Posted November 8, 2010 I was referring to the macro usefulness itself, I don't see how this would resolve the problem mentioned in the topic. My intention was to suggest an entirely different way of designing your macro(s) as I believe that the code you have written with the multiple nested Repeat loops has no chance of being visible (and therefore viable) in the way you want. In fact, display of this code has caused me several problems, some of which have caused ME to crash. So if my idea is useful (and you have indicated that it is), then I think you should abandon the approach you have adopted, and redesign and rewrite your macro using the logic I outlined. Quote Link to comment Share on other sites More sharing options...
arekowczarek Posted November 8, 2010 Author Report Share Posted November 8, 2010 My intention was to suggest an entirely different way of designing your macro(s) as I believe that the code you have written with the multiple nested Repeat loops has no chance of being visible (and therefore viable) in the way you want. In fact, display of this code has caused me several problems, some of which have caused ME to crash. So if my idea is useful (and you have indicated that it is), then I think you should abandon the approach you have adopted, and redesign and rewrite your macro using the logic I outlined. You got me confused here. Where exactly did I indicate that you're idea was useful? And what idea?? The only way to redesign the script would be to create a brand new numbers combination generator (thats what the huge loop does). I stand by my opinion that there IS NOT a different way to do it than the one I used in the macro. Can you suggest a macro that will provide all combinations within a set of elements? For 5 element set it would need to provide these combinations: 1 2 3 4 1 2 3 5 1 2 4 5 1 3 4 5 2 3 4 5 Although for 5-element set you could even predefine all the combinations (only 5) in a text file/variable or whatever, but what sort of a combination generator do you suggest that would return 200 combinations of 201-element set? In addition if I need to find a 5-element combination within a 20-element set all I need to do is change one variable value manually - and then the macro looks for 5 elements out of 20 element set instead the 19 out of 20, which means huge flexibility. 5 out of 20 is 15504 combinations. No way to predefine them if that's what on you're mind. EDIT: Or if that was you're idea: - Create an array of n rows by 200 integer columns (where n is the number of rows you will process). - Populate the array with the pixel values - Sort the array - Eliminate duplicates (do you need to remember eliminated line numbers?) - Process the array to determine the smallest number of elements that render each line unique - Create output Then I generally agree because this is the idea of how macro works at the moment. The the implementation is the problem. (well it's not to me cause the macro works and I don't see the necessity or even possibility to rewrite the script) Process the array to determine the smallest number of elements that render each line unique is exactly the part for which combinations sequences have to be used. You did not explain how to do it. And I figured I need combinations to process the array elements. To generate the combinations I used the multiple repeat commands. As I said, I don't see any other way to generate combinations. And without combinations I don't have the slightes idea how to process the array. Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 8, 2010 Report Share Posted November 8, 2010 Where exactly did I indicate that you're idea was useful? And what idea?? Well, I'm merely trying to follow along here, but I'd have thought it was in Post #7 where, in response to Paul's question "Is this useful?" you replied "- Hell yes." -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
arekowczarek Posted November 8, 2010 Author Report Share Posted November 8, 2010 Well, I'm merely trying to follow along here, but I'd have thought it was in Post #7 where, in response to Paul's question "Is this useful?" you replied "- Hell yes." -- Terry, East Grinstead, UK Yes, but in post # 9 I'm explaining that I thought that by the "Is it useful?" question he meant "Is the macro you have useful?". Now, what would give me the impression? The fact that the whole concept he provided above that question is the SAME concept my macro works at the moment. Plus he asked "Does this work as a concept [...]?. So I thought he was just describing my macro's concept to make sure he gets it right (because he didn't understand the way the macro works). So yes, his concept is right, I agree, but it's not different from the concept macro works on now. Nothing revelatory there. Quote Link to comment Share on other sites More sharing options...
paul Posted November 9, 2010 Report Share Posted November 9, 2010 Yes, but in post # 9 I'm explaining that I thought that by the "Is it useful?" question he meant "Is the macro you have useful?". Now, what would give me the impression? The fact that the whole concept he provided above that question is the SAME concept my macro works at the moment. Plus he asked "Does this work as a concept [...]?. So I thought he was just describing my macro's concept to make sure he gets it right (because he didn't understand the way the macro works). So yes, his concept is right, I agree, but it's not different from the concept macro works on now. Nothing revelatory there. One final contribution from me: I think your English is letting you down badly here. The point of outlining the concept to you was not to show you that I understood your concept, but to try and persuade you to think about your puzzle from a new angle. Nowhere in my outline is there any suggestion that you have to determine "all combinations within a set of elements"; indeed, it is this very notion that is causing you all your problems. Your insistence on calculating all combinations is exactly what is leading you astray. I don't see the necessity or even possibility to rewrite the script In which case I think you're on your own because you do not appear at all receptive to other suggestions. You did not explain how to do it. This is why I prefixed my text with the words: don't let's worry about the implementation at this stage Quote Link to comment Share on other sites More sharing options...
arekowczarek Posted November 9, 2010 Author Report Share Posted November 9, 2010 The point of outlining the concept to you was not to show you that I understood your concept, but to try and persuade you to think about your puzzle from a new angle. What new angle? The concept you presented was just describing how the macro works now. Nowhere in my outline is there any suggestion that you have to determine "all combinations within a set of elements"; indeed, it is this very notion that is causing you all your problems. Your insistence on calculating all combinations is exactly what is leading you astray. I agree that the combination part is causing the trouble. But how is the macro supposed to now which positions of the text variable should be processed at each given time? This is simple maths, really. Combinations. It's like Lotto. To present a list of all possible draw outcomes you HAVE TO use combinations. If you know a different way - please do share. Calculating all combinations is necessary, if you think otherwise you really (and I don't mean to be rude here) dont't know what you're talking about. All one could do is try to generate the combinations without the use of multiple loops. I know I can't do it, and until someone presents/describes a different way to do it in ME, I will stand by my opinion that it is impossible. In which case I think you're on your own because you do not appear at all receptive to other suggestions. Honestly, what suggestions? Paraphrasing, the general suggestion you provided was something like: “You did it wrong. I would do it better. I can’t say how cause I didn’t try to. I just know I would.” Sorry, but this kind of suggestion doesn’t help at all. It's just empty words. Apart from the above, in the first topic I stated that I needed a way to “expand the script editor window so I can see all the lines.” I clearly stated that, I didn’t say I wanted to rewrite the macro to make it fit the window, which means your English is letting you down as well. If your car doesn’t fit into the garage you don’t buy a smaller car. You extend the garage. I know I would. Anyway, thanks for all your contribution Paul. Wish it helped. __________________________________________________________________________________________ Today I noticed that the slider DOES EXIST when looking at the script in the Direct Editor view (and I can see all the lines easily all the way through). However, I find it harder to edit commands in the direct editor and to navigate within the script (no lines numbers available on the side). So I requested the horizontal bar as a feature from ISS. Tracking no. [iSS9224] Quote Link to comment Share on other sites More sharing options...
Cory Posted November 17, 2010 Report Share Posted November 17, 2010 This is an interesting macro you are writing. I do not have the time to comprehend what you are doing but I wanted to make a few observations that may or may not apply. You post is really about the scroll bars and that needs to be reported to ISS as a bug. But the reason ISS has probably never considered this is that no one should ever have more than about a half dozen nested conditions. Anytime one sees huge nested conditions like this the train has gone off the rails. In my experience there is always a way to avoid it. Even if you were looking for words from the bible that don't follow any mathematical order you could at least load all the words used in the conditions into an array and numerically process the array. Sometimes there's a mathematical way, sometimes it's tables of values, sometimes it's a little unconventional but there's always a way. I don't know how your macro is working with the 2D bar code but you might want to induct the data value of the bar code into a variable and process that. If you save a graphic like this as a BMP it's fairly simple to decode the BMP into usable data. I wrote a post here about it somewhere. In this case I bet if you save the bar code to a BMP each dot will be something like 4X4 pixels in which case it would be really simple to convert into a string of ones and zeros by processing the bytes of the BMP. Helluva lot better than Get Pixel Color and hyper fast. There are DLLs that will decode bar codes for you. Might want to check some of them out. Also I know IRIS and other OCR products have the ability to take an image of a bar code from a scan pen or whatever and decode it. Hell, my Android cell phone will decode bar codes! I wish I could play with this one. Sounds like fun. Good luck! Quote Link to comment Share on other sites More sharing options...
arekowczarek Posted November 17, 2010 Author Report Share Posted November 17, 2010 You post is really about the scroll bars and that needs to be reported to ISS as a bug. But the reason ISS has probably never considered this is that no one should ever have more than about a half dozen nested conditions.I don't recall having more than 3 nested conditions ever before. And I am against such nesting myself. But it was (still is) the only way I could think of to process the input data. As for reporting the problem, I requested the horizontal bar as a feature Tracking no. [iSS9224]. Anytime one sees huge nested conditions like this the train has gone off the rails. In my experience there is always a way to avoid it. Even if you were looking for words from the bible that don't follow any mathematical order you could at least load all the words used in the conditions into an array and numerically process the array. Sometimes there's a mathematical way, sometimes it's tables of values, sometimes it's a little unconventional but there's always a way.I know what you're saying, but storing like, I don't know , 10 000 000 or more words into an array? And you still would need a macro to generate all the words in first place. Plus the words have to be generated only using "letters" available for use in this particiular case.I'm pretty sure it's the mathematical way I am using at the moment. I spent like two days trying to figure a unique combination generator and this proved to be the most efficient. I don't know how your macro is working with the 2D bar code but you might want to induct the data value of the bar code into a variable and process that.Not sure I follow here. It sort of works like reading barcodes. The idea of the macro is, while having i.e. 2 barcodes, find the least number of pixels that will distinguish one barcode from another. Of course I could read the whole i.e. 16 pixels but the point is it's not efficient. It's not efficient versus only 1 pixel that is necessary to distinguish one barcode from another. That is, provided we know that only 2 barcodes can appear. If there were three barcodes we would need 2 pixels to distinguish one from the others. If you save a graphic like this as a BMP it's fairly simple to decode the BMP into usable data. I wrote a post here about it somewhere. In this case I bet if you save the bar code to a BMP each dot will be something like 4X4 pixels in which case it would be really simple to convert into a string of ones and zeros by processing the bytes of the BMP. Helluva lot better than Get Pixel Color and hyper fast.Of course I have all the lines (or: "barcodes") converted into text strings before the MAIN macro starts. During its work the macro doesn't read any pixels off the screen, it works with the text strings that have the pixels values pre-set into them. Reading every combinations of pixels off the screen during macro's run would slower the whole process like a hundred times. There are DLLs that will decode bar codes for you. Might want to check some of them out. Also I know IRIS and other OCR products have the ability to take an image of a bar code from a scan pen or whatever and decode it. Hell, my Android cell phone will decode bar codes!Now, the data I work with is in no way regular barcodes. The lines are just random 0s and 1s BUT not only, sometimes they are 0s,1s,2s,3s,4s,5,s etc. That's because my "barcodes" happen to have 10 or even more colours. Let's assume that I only deal with black and white barcodes that are 100-pixels wide. What may be confusing: I know I could read 100 pixels of each bar and it would give me a different binary representation. But that's the whole point of the macro. To limit the number of pixels needed to distinguish one barcode from another. And as stated above, 1 pixel would be enough to distinguish 2 monochromatic barcodes from each other. I kept puting the barcodes into quotation marks since I do not work with barcodes. They are just pixels retrieved from a picture like i.e. a Mah-Jong tile. And on a Mah-jong example, I need to know which pixels to read to distinguish one tile from the others. Reading a Mah-jong tile all way through would be like 1000 pixels. And yes, it would be unique set of pixels for each tile. But reading 1000 pixels every time I want to know which tile is displayed in a particular spot? No way it could be efficient. Hence the cobination macro. It limited the number of pixels necessary to distinguish one tile from the others down to only 10 pixels (or 11, I don't recall). Reading 1000 px vs 10 px? Certainly worth the hassle. I wish I could play with this one. Sounds like fun. Good luck! Thanks Cory, but I consider the combination macro finished, and since I don't need to tamper with its entrails anymore or do anything else but use it, I'll just let it be. I don't believe there's away to eliminate the nested loops in this particuar macro, so, unless somebody provides a totally different idea of the whole process, I'll just leave the macro alone. I'd love to be proven wrong on this. But for now, the macro does the job it was designed for. The only fault it has is: it doesn't fit the screen. If only I had a 100 inch LCD! (hope you're reading this, Santa) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.