Arrays

J

John

Sam,
Let's assume you want to save all the IDs of a project in an array and
that the project summary task option if off and the file is not a
consolidated master file with inserted projects. This is one way to do
it.

Sub SavIDs()
Dim IDs() as Integer
NumTsk = ActiveProject.Tasks.Count
ReDim IDs(NumTsk)
For i = 1 to NumTsk
IDs(i) = i
Next i
End Sub

John
 
J

JackD

Or perhaps if you want to save the task unique id
in the for loop use:

IDs(i) = activeproject.tasks(i).UniqueID

-Jack
 
S

Sam

Thanks!

Is it possible to print the whole list/array of IDs at
the same time.
One thing I have to do is for instance to take the
largest finish. How can I do this?

Thanks in advance,
Sam
 
K

Kent

How can I use multidimensional arrays?

I would like to save both the ID and start and finish.
Array(ID, Start, Finish)

Thanks in advance,
Kent
 
J

John

Kent,
A multidimensional array is not needed to store the three values. It can
be used, but it is probably harder to keep track and in this case, it
will waste memory allocation because most of the array cells won't be
used. I would simply use a single dimension array for each of the fields
you want to save. For example:
IDs(i) for ID
St(i) for Start
Fin(i) for Finish

John
 
J

John

Sam,
What do you mean by "print the whole list of IDs at the same time"? That
can be done now by simply printing just the ID column of a view.

Can you explain what you mean by "take the largest finish"?

John
 
R

Rod Gill

If you want something like the latest finish, the easiest result comes from
using Project to do the work. Try sorting by Finish date then read the date
of the last task's finish field. Make sure in the sort you haven't got
renumber tasks enabled. If you do, then either force the setting off before
sorting or don't save changes.

--
Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.projectlearning.com/
 
J

JackD

Sure, declare a date variable (call it LastOneDone) for example.
Then set it to zero.
within a loop just compare task.finish to LastOneDone and if it is greater
set LastOneDone to task.finish.

-Jack
 
J

JackD

John, I disagree. Often you want to keep the ID, Start and Finish for each
task.
That way MyArray(i,i,i) would refer to the ID, Start and Finish for that
task
Since every task has a start and a finish all the array cells would be used.
If there weren't a 1:1 correspondence then I'd agree, but not in this case.

For a multi-dimensional array simply declare it with the size
For example a 3x10 array would be
MyArray(10,10,10)
 
J

John

Jack,
I guess it's a matter of choice. My point is that with MyArray(10,10,10)
the system has to allocate 10 x 10 x 10 locations of whatever size the
data type demands whereas only 3 x 10 of those locations will be used.
For example, the location MyArray(1,2,1) [depending on the option base]
and a host of others are not used. Therefore, I tend to use individual
arrays that only take up as many memory locations as necessary. I also
find it easier to keep track of single dimensional arrays.

Granted, with the typical RAM in today's PCs, the additional amount of
memory consumed by unsued cells of a multidimensional array is a drop in
the bucket so although my argument may be technically sound, it is
probably mute. Keeping track of elements of multidimensional arrays is
probably the better argument although I do use them myself occasionally.

John
 
L

Lars Hammarberg

Unless you're interested in minimising the size of the array, why not simply
use a Tasks variable holding all the tasks in the project?
e.g.:
dim mytasks as Tasks
set mytasks = activeproject.tasks

then you could access any task data by

lngID = mytasks(n).ID
dtStart= mytasks(n).start
etc.
 

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