VBA to VB.NET Issue

  • Thread starter Thread starter Michael A.
  • Start date Start date
M

Michael A.

Hello All,

To start with, the following code works in VBA without issue:

Set Tsvs = resAsgnmt.TimeScaleData(prStart, prEnd,
pjAssignmentTimescaledWork, pjTimescaleMonths)
'Obtain the timescale data for each resource
j = 2
For Each Tsv In Tsvs
allResources(i, j) = allResources(i, j) + Val(Tsv.Value)
resourcesTotalWork(i, j) = resourcesTotalWork(i, j) + Val(Tsv.Value)
j = j + 1
Next Tsv

I convert this into Visual Studio as - it is just about identical:

tsvs = resAsgnmt.TimeScaleData(prStart, prEnd,
MSProject.PjAssignmentTimescaledData.pjAssignmentTimescaledWork,
MSProject.PjTimescaleUnit.pjTimescaleMonths)
j = 2
Dim tsv As MSProject.TimeScaleValue
For Each tsv In tsvs
resourceWorkAlloc(i, j) = resourceWorkAlloc(i, j) + Var(tsv.Value)
resourcesTotalWork(i, j) = resourcesTotalWork(i, j) + Var(tsv.Value)
Next tsv

The problem:
When the code cycles through the 'tsv' values, it works for some instances
but then all of a sudden throws an unhandled unexpected error as follows:

System.Runtime.InteropServices.COMException was unhandled by user code
ErrorCode=-2146827284
HelpLink="D:\Program Files\Microsoft Office\Office12\VBAPJ.CHM#131072"
Message="An unexpected error occurred with the method."
Source=""

I see here that for some reason it doesn't like the empty string and yet it
the code has successfully processed empty strings earlier.

Would anyone have any thoughts as to why this would occur and what I may do
to resolve?

I appreciate your time and consideration.


Kind regards
Michael A.
 
Michael,

Did you put Option Strict ON in top of your program.
Mostly with that you see direct almost all the problems that can happen by
converting.

Cor
 
Hello Cor,

I didn't originally have Option Strict On, so I changed that which forced me
to change a whole stack of other things. However, I still get the same
COMexception error when referencing tsv.Value. I have not problems accessing
tsv.Startdate or tsv.Item for instance, but tsv.Value never works.

What do you think about this?


Thanks
Michael
 
Back
Top