Creating MS Project Addins using VB.NET

D

Duncan

Hi All,

I'm fairly new to creating office addins and have stumbled across the
following problem that I hope you could help me out with.

The concept:
I have a windows form based addin that creates data graphically and stores
it in a custom class, instances of which are referenced using "Items(i)"
where i is the indexing integer. The plan is once having created this data on
the form, I could use it to populate MS Project with Tasks where one instance
of my Items class corresponds to one Task in project.

The Problem:
The issue I have is that when using the function:

CurrentProject.Tasks.Add(NewTask)

This works for one task, but I wish to place this line in a Do Loop and at
the moment whenever this line is executed, the task is added, but the addin
closed before getting to the next command. When stepping through the code, it
doesn't show any errors or out of bound variables, it simply executes Add
function and drops back to project closing the addin in the process.

Supporting info:
The current instance of MS Project is declared as follows:

(in connect.vb OnConnection):
applicationObject2 = application

(in connect.vb MyMenuEventHandler):
'show form with tools on
Dim PCLMngForm As New PCLMngFrm

'set appinstance to this application
PCLMngForm.AppInstance = applicationObject2
PCLMngForm.ShowDialog()

(in PCLMngFrm.vb):
Public Items(10000) As Item
Public AppInstance As Microsoft.Office.Interop.MSProject.Application

(in PCLMngFrm.vb AddToProjectCmd_Click):
Dim CurrentProject As Project
CurrentProject = AppInstance.ActiveProject

Dim NewTask As Task
Dim i As Integer = 0
Do Until Items(i) Is Nothing
NewTask =
CurrentProject.Tasks.Item(CurrentProject.Tasks.Count)
NewTask.Name = Items(i).Name
NewTask.Notes = Items(i).Notes
CurrentProject.Tasks.Add(NewTask)
i += 1
Loop

(System / Software Config):
Windows 2k SP4
Visual Studio 2003 Pro
MS Project 2003 Standard

It's probably something silly that I've missed, but any help would be
greatly received.

Thanks in advance,

Duncan
 
R

Rick Williams

Just a thought, but perhaps you could do a Save at the end of the loop
before it tries to execute again? Also, you might use a simple Do...Loop
instead of Do Until and have a line within the loop which checks a specific
condition, which if True, executes Exit Do.
Hope this helps,
Rick
 
D

Duncan

Thanks Rick. I tried your suggestions, but I'm afraid they had the same
result as my code.

However, I've now solved the problem. The issue was with declaring the form
with a ShowDialog() method. This seems to instruct Project (or any office app
you're running an addin inside) to wait for feedback from the Dialog box and
assume that the first feedback it gets is the only feedback it is going to
get and so closes the dialogue box. I simply changed the ShowDialog() to a
Show() and it works perfectly.

Thanks for your input anyway Rick - much appreciated.
 

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