PC Review


Reply
Thread Tools Rate Thread

Chart problem - works in VBA, but not VB.Net

 
 
rogercnorris@yahoo.com
Guest
Posts: n/a
 
      9th Nov 2006
The following code was ported directly from some older VBA code that we
have. The VBA code works fine, but when we run it from VB.Net we get
an exception. What might be the problem?

The VB.Net code is simply trying to add a data series to a chart (using
Excel 2003). This is the code:

----

Dim worksheet as Excel.Worksheet
Dim xvalues, yvalues as Excel.Range

..
..
..

' Create new chart object embedded in the worksheet
Dim chart As Excel.Chart = CType(worksheet.ChartObjects,
Excel.ChartObjects).Add(400, 0, 640, 480).Chart
chart.ChartType = Excel.XlChartType.xlXYScatterLines

' add data series to the chart
CType(chart.SeriesCollection,
Excel.SeriesCollection).Add(Source:=application.Union(xvalues,yvalues))

----

When the final line of code is executed, we get the following error:

System.InvalidCastException
OleAut reported a type mismatch.
Stack trace:
at Microsoft.Win32.OAVariantLib.ChangeTypeEx(Variant source, Int32
lcid, Int32 cvType, Int16 flags)
at Microsoft.Win32.OAVariantLib.ChangeType(Variant source, Type
targetClass, Int16 options, CultureInfo culture)
at System.OleAutBinder.ChangeType(Object value, Type type, CultureInfo
cultureInfo)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Microsoft.Office.Interop.Excel.SeriesCollection.Add(Object Source,
XlRowCol Rowcol, Object SeriesLabels, Object CategoryLabels, Object
Replace)


Oddly enough, the chart *is* created and the data series appears to
have been added properly. So what can we do to prevent this exception
from being thrown?

Some other relevant information... We're working in VB.Net 2003. The
interop library we're using is the Microsoft Excel 11.0 Object Library.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i scan a chart into microsoft works jeff??? Microsoft Powerpoint 2 13th Apr 2008 02:53 AM
Wierd problem- R8500 AGP works, PCI card works, R9700pro won't run POST, on A7N8X-E Ken Maltby Computer Hardware 8 14th Mar 2006 07:02 AM
Wierd problem- R8500 AGP works, PCI card works, R9700pro won't run POST. Ken Maltby ATI Video Cards 2 11th Mar 2006 01:35 AM
After rebooting my PC works, works, works! Antivirus problem? Adriano Anti-Virus 2 15th Dec 2003 05:30 AM
Re: After rebooting my PC works, works, works! Antivirus problem? Adriano Anti-Virus 1 15th Dec 2003 12:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:38 PM.