TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Windows Forms and opening MS Project.mpp File (http://forums.techarena.in/software-development/1031769.htm)

jaksel 03-09-2008 07:38 PM

Windows Forms and opening MS Project.mpp File
 
I am developing a Windows Forms application in VB.NET using Visual Studio 2008. I am attempting to open an MSProject.mpp file and iterate through the tasks. Here is my code from Form1 so far:

Dim mFileName As String
'When looking at the project Window drop down, determine the index number of the file
Dim iFileIndex As Int16
Dim pjApplication As New Microsoft.Office.Interop.MSProject.Application
Dim mTasks As Microsoft.Office.Interop.MSProject.Tasks
Dim mTask As Microsoft.Office.Interop.MSProject.Task
'Get an mpp file, no error checking at this time
OpenFileDialog1.ShowDialog()

mFileName = OpenFileDialog1.FileName.ToString()
TextBox1.Text = mFileName.ToString

pjApplication.FileOpen(mFileName) 'FileOpenEx(SourceFile) ????
pjApplication.Visible = True
pjApplication.AppMinimize()

Debug.Print("File Opened: " & mFileName.ToString)

iFileIndex = pjApplication.ActiveProject.Index
Debug.Print("Active Project: " & pjApplication.ActiveProject.Name.ToString)
mTasks = pjApplication.ActiveProject.Tasks
Debug.Print("Task Count: " & mTasks.Count.ToString)
Debug.Print("Source File Index: " & iFileIndex.ToString & " Task Count: " & mTasks.Count)
'************************************************* *******
'This is where it dies: it tells me mTask is set to "Nothing" What do I need??
'************************************************* ********
For Each mTask In mTasks 'pjApplication.ActiveProject.Tasks
'the real work goes here
Next mTask

So it does not like the For Each loop for some reason. It is the mTask that seems to be doing it. All the Debug.Print statements return expected values.

unlimitedtech 03-09-2008 07:50 PM

Quote:

For Each mTask In mTasks 'pjApplication.ActiveProject.Tasks
'the real work goes here
Next mTask
I have seen your code and I didn't find any statement where you have assigned anything to mTask. So how can you run the For loop if nothing is assigned to it. For loop need some value to run the statements in it.

jaksel 03-09-2008 08:53 PM

Yes, that is my question ... what line of code do I need to assign something to mTask?

mTask is dimensioned, and is set to null. I need to be able to iterate through the mTasks collection. Doing it this way works fine in VBA, but I am missing the secret line of code that will initialize mTask to something even though it is of type Task.


All times are GMT +5.5. The time now is 03:40 AM.