looping through variables

S

Steve

I have the following problem. I have several tables in a document and I need
to work with the tables in a certain style. So I wrote a piece of code that
loops through the tables, checks te style and if it is a match creates a
variable in the variable collection of which the name is a counter for the
matches and the value is a counter for the tables. This works fine, but when
the matches exceed 10 the following occurs:

While looping through my variables by itemnumber the order is changed. I use
the following code:
For i = 1 To ActiveDocument.Variables.Count
iTmp = ActiveDocument.Variables(i).value

and now expect to see my matches from 1,2,3,....,9,10,11... and so on...
however I get: 1,10,11,12,..,2,3,4...
Am I doing something wrong?
 
J

Jay Freedman

I have the following problem. I have several tables in a document and I need
to work with the tables in a certain style. So I wrote a piece of code that
loops through the tables, checks te style and if it is a match creates a
variable in the variable collection of which the name is a counter for the
matches and the value is a counter for the tables. This works fine, but when
the matches exceed 10 the following occurs:

While looping through my variables by itemnumber the order is changed. I use
the following code:
For i = 1 To ActiveDocument.Variables.Count
iTmp = ActiveDocument.Variables(i).value

and now expect to see my matches from 1,2,3,....,9,10,11... and so on...
however I get: 1,10,11,12,..,2,3,4...
Am I doing something wrong?

Yes, you are. <g>

The Variables collection is being returned to you in alphabetic order,
not in the order of creation. To work around this, name the variables
with two digits: 01, 02, 03... 10, 11, ... It's simplest to use the
Format function to create these names.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top