Simple Repeat? Counting items

I am having trouble with a simple repeat loop”I though I had it kicked.
I am trying to get the item’s location within a word. In the example below I am trying to find the item’s count to where the “<” lies. In other words it should be “9”. FWIW, the are characters that appear because of an XML tag. I thought if I could count sequentially from item 1 until I hit a character not equal to “^9” or “/”.

00/00/00

My script below yields this error:
Adobe InDesign CS2 got an error: Can’t get item (item 1 of “0/00/00.”) of document 1.

set j to 1
					repeat with j in theSelDate2
						try
							if item j is equal to "^9" then set j to j + 1
							display dialog j
						end try
						try
							if item j is equal to "/" then set j to j + 1
							display dialog j
						end try
					end repeat

Hi Jeff,

you’re mixing up the repeat forms

If you need to access to the value of the index variable, use


repeat with j from 1 to count theSelDate2
	if item j of theSelDate2 is equal to "^9" then
		display dialog (j as text)
		-- do something
	else if item j of theSelDate2 is equal to "/" then
		display dialog (j as text)
		-- do something else
	end if
end repeat

Note: the index variable will be increased automatically

If the index variable doesn’t matter, use the repeat with oneItem in theItems form


repeat with j in theSelDate2
	if contents of j is equal to "^9" then
		-- do something
	else if contents of j is equal to "/" then
		-- do something else
	end if
end repeat

Note: As AppleScript doesn’t dereference the value of the list item automatically in a boolean comparison,
the scripter must do this (with the contents of form)

If the value of

Stefan,
Thank you!
That’s what I was looking for”Excellent! And yes the index variable is what I am after.

btw, one more question.

How do I count backwards from the last item in a word. I will have to do that in certain instance as well. And then assign a variable from variable j to variable k in theSelDate. (It that makes sense?)

counting backwards is (if I understand that right)


repeat with j from (count theSelDate2) to 1 by -1
	if item j of theSelDate2 is equal to "^9" then
		copy j to k
		display dialog (k as text)
		-- do something
	else if item j of theSelDate2 is equal to "/" then
		copy j to k
		display dialog (k as text)
		-- do something else
	end if
end repeat

I want to kick myself!
That’s it. Thanks once again.