Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-09-2008
Member
 
Join Date: Nov 2006
Posts: 3
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.
Reply With Quote
  #2  
Old 03-09-2008
Member
 
Join Date: May 2008
Posts: 186
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.
Reply With Quote
  #3  
Old 03-09-2008
Member
 
Join Date: Nov 2006
Posts: 3
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Windows Forms and opening MS Project.mpp File"
Thread Thread Starter Forum Replies Last Post
Cannot find file error when opening a file in Windows WalshJ Vista Help 18 16-06-2012 06:36 AM
MS Project 2010 does not work after opening a mpp-file Kane Microsoft Project 5 21-03-2012 03:18 PM
Internet explorer web file is not opening in windows 7 ZiGmA4321 Windows Software 3 17-01-2011 06:08 PM
How to open a MS project 2007 file in MS project 2010 pqmot Windows Software 3 30-12-2010 04:41 PM
Error opening Project 2007 file after using project 2010 Jio Microsoft Project 3 10-11-2010 07:27 PM


All times are GMT +5.5. The time now is 03:59 PM.