I'm going to argue this one -- it is always beneficial for variables to have meaningful names, and more obvious information is nearly always better. When you get an error in a couple of months time and need to work out what's missing, which helps more?
- zz_cb07
- Alt_Text_3
- Alt_Text[3]
- ImageDetails[3].Alt_Text
For the first you'll need to work your way through your macro, maybe do some finger counting. For the rest (single variables, array, and JSON) you can see at a glance that image 3's alt text is the problem.
But that's something to consider for future macros. For this one, treat it just like a printed sheet that you are extracting info from to a bunch of individual Post-Its. Most people would go down the sheet one line at a time, see if the start of the line matched anything they were looking for, and if so they'd write that info on a newly-labelled Post-It.
In pseudo-code:
set my post-it counter to 1
for each line in the text
if the start of the line matches something I'm looking for
copy the line to a new post-it labelled with the post-it counter number
increase the post-it counter by 1
end if
end for
Now consider the "if..." bit of that. In this case you don't care what it matches, just that it does match -- your "fields" are in the same order throughout, so working line-by-line means they'll be written to your Post-Its in the right order.
So, re-writing the above in a more KM way:
set counter to 1
for each line in text
-- use enough for a single match AND enough that you understand the meaning at a glance
if start of line is "- Alt" or "- Title" or "- Description"
then
set variable zz_cb<counter> to line
set counter to counter + 1
otherwise
-- there is no otherwise! Saying that shows you didn't forget...
end if
At which point you can build the macro almost line-for-line from the pseudo-code:
Image Attributes (Multi Var).kmmacros (10.0 KB)
Image
(As before, I've used local variables for testing -- delete "Set Variable 'Local_zz_...' " and enable "Set Variable 'zz_...' " to use globals.)
And you can make it more concise by replacing the three "If..." conditions with one: