cyberchief Posted May 17, 2005 Report Share Posted May 17, 2005 I am building a macro that will log a customer billed amount for an entire history into an excel spreadsheet. I will have the Macro pull up the most current month, find the amount, and log that into %T10%. I then have it issue a command to go back 1 month and do the same. Here is where I am having issues... I want to set that next amount to %T11%... and repeat the process until there are no more invoices to go back to (if there is another previous month, set that to %T12% and keep going until screen contains "requested bill not found"). This will run in a loop for multiple accounts on a spreadsheet. Problem is that each account will have a different amount of invoices going back... 1 account could only have 2 invoices (so only T10 and T11), but some may go back 30 months. Is there a way to create the new varialbes without having to write them all out? I don't want to have to write code out to set 100 variables so that, just in case, I am covered for all months... I want it to only set the new variable IF there is a previous bill... and continue to do so until there are no more invoices. After each account's history has been logged, those figures will be input into a spreadsheet and the variables will be cleared... but I need to log up to a possible 36 or so (3 years). Quote Link to comment Share on other sites More sharing options...
Nicolas Posted May 17, 2005 Report Share Posted May 17, 2005 I only see one solution : 1) create a small macro for ONE month with %T10% 2) see how it looks like in the "direct editor" window : you should see %T10% somewhere (or at several places) now you can dynamically create the same macro (as in step 2) in variable %T1% for any %Tx% by replacing all these %T10% by %T%N1%% for instance, where %N1% is incremented for every month, beginning with 10 ... you'll launch this dynamic macro with the Run Macro in Variable %T1% command schematically (sorry I don't have time to produce real ME code) : %N1%=10 loop on months set %T1% with your "template" in which %T10% is replaced with %T%N1%% run macro in variable %T1% increment %N1% end loop on months Quote Link to comment Share on other sites More sharing options...
floyd Posted May 17, 2005 Report Share Posted May 17, 2005 Nicolas has it right. Here is an example that you can run: // Set the counter (placeholder for the next string). Variable Set Integer %N10% to 10 // Infinite loop Repeat Until %N1% <> %N1% // Increment the next string placeholder (T11 through T46) Variable Modify Integer: Inc (%N10%) // Set a string to a random character to use as an example. // This would actually be a string that holds this month's data. Variable Set String %T1% to Random Letter // Exit the loop if the random character is a "Z" or if we have filled 36 string variables // This would actually be: Exit if no more months found or if we have gone back 36 months. If Variable %T1% = "Z" OR If Variable %N10% > 46 Repeat Exit End If // Copy the current string to the next placeholder string Variable Set String %T2% "<TMVAR2:09:%N10%:01:000:000:>" Run Macro in Variable %T2% Repeat End <REM2:Set the counter (placeholder for the next string).><IVAR2:10:01:10><REM2:><REM2:Infinite loop><REP3:08:000002:000002:0001:1:01:N1><REM2:><REM2:Increment the next string placeholder (T11 through T46)><NMVAR:08:10:0:0000001:0:0000000><REM2:><REM2:Set a string to a random character to use as an example.><REM2:This would actually be a string that holds this month's data.><TVAR2:01:12:><REM2:><REM2:Exit the loop if the random character is a "Z" or if we have filled 36 string variables><REM2:This would actually be: Exit if no more months found or if we have gone back 36 months.><IFVAR2:1:01:1:TZ><OR><IFVAR2:2:10:4:T46><EXITREP><ENDIF><REM2:><REM2:Copy the current string to the next placeholder string><TVAR2:02:01:<TMVAR2:09:%N10%:01:000:000:>><RUNMACVAR:2><REM2:><ENDREP> Quote Link to comment Share on other sites More sharing options...
cyberchief Posted May 17, 2005 Author Report Share Posted May 17, 2005 Thanks Nicolas and Flyod. I will look into this. I don't quite understand the code... but if I stare long enough... I think it will make sense!!! Thanks again! 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.