Simple Repeat Question (return variable instead of dialog box)

I am stuck trying to figure out how to capture a variable the equals the sum or total amount of times a repeat statement is run? It should be simple but it is not for me.

For instance, in my script below you will see the part of my code that is repeating dialog boxes with a value of one.

Rather than having a dialog box pop up, i.e. six times, I would like to attach a number variable that knows how many times this had to happen. For instance “6”.

Then later in my script I could compare this hypothetical number “6” to another number.

I realize I have asked a lot. But I appreciate all of your help.

Many thanks,
Jeff

tell application "Adobe InDesign CS2"
	tell active document
		--try
		set theRoot to (item 1 of XML elements) -- the root element 
		set theElements to every XML element of theRoot
		set theElementsCount to count of theElements
		display dialog theElementsCount
		set numberAPNBox to count of (every XML element of theRoot whose name of markup tag is equal to "aPNBox")
		set theAPNBoxes to every XML element of theRoot whose name of markup tag is equal to "aPNBox"
		display dialog numberAPNBox
		repeat with x in theElements
			try
				set y to every XML element of x
				if (name of markup tag of x is equal to "aPNBox") then set theSubElements to every XML element of x
				
				-------------- This repeat statement below is what I want to capture as a number variable equal to how many times it runs ----------
				repeat with y in theSubElements
					if (name of markup tag of y is equal to "expirationdate") then set expCount to (count of y)
					display dialog "Eventually I want to figure out how to add up all of these 1's being returned. So if this dialog had to pop up 6 separate times, I would somehow have a variable that equals six." & expCount
				end repeat
			end try
		end repeat
		--end try
	end tell
end tell

You could count theSubElements.

Bruce,
If you know how please let me know. I have tried every which way to count the subElements. But nothing has worked. I am really not kidding here. If you saw how tired I am you would believe me :frowning:

Don’t use your app, but if you’re trying to count trues and falses, then:

set testList to {true, true, false, true, false, true}
set tTrue to 0
set tFalse to 0
repeat with I in testList
	if I then
		set tTrue to tTrue + 1
	else
		set tFalse to tFalse + 1
	end if
	set tTotal to tTrue + tFalse
end repeat
{tTrue, tFalse, tTotal} --> {4, 2, 6}

Adam,
I owe you one. With a bit of work this should work. I hope I could set the list items to a variable if the variable is a number? I will need to do that because the list item will always change depending upon what’s in the document.

Thanks again,
-Jeff

Hi, Jeff;

You can coerce 0 and 1 to boolean, but not just any number:

set {X, Y} to {1, 0}
{X as boolean, Y as boolean} 
--> {true, false}

Doesn’t work in reverse.

Sorry for taking so long to get back to you on this. This was great in many more ways than expected. To be honest, I didn’t have to coerce a true/false from 0/1, but it is great to know. What you really showed me was my stupidity in not realizing the fundamental aspect of adding incremental values to a variable within a repeat loop. This was all I needed to get the job done. I couldn’t have done it without you.

Thank you.
-Jeff

Like this?

{false as integer, true as integer}
--> {0, 1}

Don’t know what I was thinking then.

Maybe you were thinking of number/real; That doesn’t work.

ahh – Number. :frowning: