run time error

samichac
05-20-2008, 03:58 PM
hello everybody.

I've been working lately on a vba project. i used several components such as excel spreadsheets and charts....

the thing is that i wanted to make an exe application... I discovered that i could open the form on vb6 and i could build the executable format. Well i did that and it worked perfectly: the program works fine(it is a calculation program). The only problem that i'm facing is the graphs i needed the program to draw.

when i compile and run the project i receive run time error 2147024809.....

the code (graph only the rest is 24 pages):

Sub Window_OnLoad()

Dim chConstants

' clear +input of the values in the spreadsheet1

Spreadsheet1.ActiveSheet.Cells.Clear
Spreadsheet1.ActiveSheet.Cells(1, 1).Value = 0
Spreadsheet1.ActiveSheet.Cells(2, 1).Value = 1
Spreadsheet1.ActiveSheet.Cells(3, 1).Value = 2
Spreadsheet1.ActiveSheet.Cells(4, 1).Value = 3
Spreadsheet1.ActiveSheet.Cells(5, 1).Value = 4

Spreadsheet1.ActiveSheet.Cells(1, 2).Value = -1
Spreadsheet1.ActiveSheet.Cells(2, 2).Value = 0
Spreadsheet1.ActiveSheet.Cells(3, 2).Value = 1
Spreadsheet1.ActiveSheet.Cells(4, 2).Value = 2
Spreadsheet1.ActiveSheet.Cells(5, 2).Value = 3

Spreadsheet1.ActiveSheet.Cells(1, 3).Value = 2
Spreadsheet1.ActiveSheet.Cells(2, 3).Value = 3
Spreadsheet1.ActiveSheet.Cells(3, 3).Value = 4
Spreadsheet1.ActiveSheet.Cells(4, 3).Value = 5
Spreadsheet1.ActiveSheet.Cells(5, 3).Value = 6


' Clear the contents of the chart workspace. This removes
' any old charts that may already exist and leaves the chart workspace
' completely empty. One chart object is then added.
ChartSpace1.Clear
ChartSpace1.Charts.Add
Set chConstants = ChartSpace1.Constants



' Set the chart DataSource property to the spreadsheet.
' It is possible to specify multiple data sources, but this example uses only one.
ChartSpace1.DataSource = Spreadsheet1

' Add three series to the chart.
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection.Add



ChartSpace1.Charts(0).Type = chChartTypeScatterSmoothLine


ChartSpace1.Charts(0).SeriesCollection(0).SetData chConstants.chDimXValues, chConstants.chDataBound, "A1:A5"
ChartSpace1.Charts(0).SeriesCollection(0).SetData chConstants.chDimYValues, chConstants.chDataBound, "B1:B5"

ChartSpace1.Charts(0).SeriesCollection(1).SetData chConstants.chDimXValues, chConstants.chDataBound, "A1:A5"
ChartSpace1.Charts(0).SeriesCollection(1).SetData chConstants.chDimYValues, chConstants.chDataBound, "C1:C5"

' Make the chart legend visible, format the left value axis as percentage,
' and specify that value gridlines
ChartSpace1.Charts(0).HasLegend = True
End Sub

and i have a code sentence highlighted in yellow:
ChartSpace1.Charts(0).SeriesCollection(0).SetData chConstants.chDimXValues, chConstants.chDataBound, "A1:A5"


it gives me a runtime error i guess it has to do with the chart component.

if someone has any idea how to fix the probleme i would be glad tout hear it

thank you very much

i'm sorry for the english mistakes (i put in some french) it was 4 AM where i live ... and it has been a week that i haven't slept well. Anyway just to tell you that with the run time error i get "the specified dimension is not valid for the current chart type". The example i gave you is working perfectly on vba but not on vb6. However i got a vba example for how to draw a chart and it works perfectly on vb6.

here is that example:

Sub Window_OnLoad()

Dim chConstants

Spreadsheet1.ActiveSheet.Cells.Clear
Spreadsheet1.ActiveSheet.Cells(2, 1).Value = "Car"
Spreadsheet1.ActiveSheet.Cells(3, 1).Value = "Sport-Utility"
Spreadsheet1.ActiveSheet.Cells(4, 1).Value = "Truck"
Spreadsheet1.ActiveSheet.Cells(5, 1).Value = "Minivan"

Spreadsheet1.ActiveSheet.Cells(1, 2).Value = "1998"
Spreadsheet1.ActiveSheet.Cells(2, 2).Value = 0.2
Spreadsheet1.ActiveSheet.Cells(3, 2).Value = 0.06
Spreadsheet1.ActiveSheet.Cells(4, 2).Value = 0.17
Spreadsheet1.ActiveSheet.Cells(5, 2).Value = 0.13

Spreadsheet1.ActiveSheet.Cells(1, 3).Value = "1999"
Spreadsheet1.ActiveSheet.Cells(2, 3).Value = 0.38
Spreadsheet1.ActiveSheet.Cells(3, 3).Value = 0.82
Spreadsheet1.ActiveSheet.Cells(4, 3).Value = 0.28
Spreadsheet1.ActiveSheet.Cells(5, 3).Value = 0.62

Spreadsheet1.ActiveSheet.Cells(1, 4).Value = "2000"
Spreadsheet1.ActiveSheet.Cells(2, 4).Value = 0.42
Spreadsheet1.ActiveSheet.Cells(3, 4).Value = 0.12
Spreadsheet1.ActiveSheet.Cells(4, 4).Value = 0.55
Spreadsheet1.ActiveSheet.Cells(5, 4).Value = 0.25

' Clear the contents of the chart workspace. This removes
' any old charts that may already exist and leaves the chart workspace
' completely empty. One chart object is then added.
ChartSpace1.Clear
ChartSpace1.Charts.Add
Set chConstants = ChartSpace1.Constants

' Set the chart DataSource property to the spreadsheet.
' It is possible to specify multiple data sources, but this example uses only one.
ChartSpace1.DataSource = Spreadsheet1

' Add three series to the chart.
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection.Add
ChartSpace1.Charts(0).SeriesCollection.Add

' Connect the chart to data by specifying spreadsheet cell references
' for the different data dimensions.
' Notice that the series name is also bound to a spreadsheet cell. Changing
' the contents of the cell "B1" will also change the name that appears in the legend.
' If you don't want this behavior, set SeriesCollection(0).Caption instead of
' using the SetData method to bind the series name to the spreadsheet.

' Series one contains sales growth data for 1998.
' Bind the series name, the category names, and the values.
ChartSpace1.Charts(0).SeriesCollection(0).SetData chConstants.chDimSeriesNames, chConstants.chDataBound, "B1"
ChartSpace1.Charts(0).SeriesCollection(0).SetData chConstants.chDimCategories, chConstants.chDataBound, "A2:A5"
ChartSpace1.Charts(0).SeriesCollection(0).SetData chConstants.chDimValues, chConstants.chDataBound, "B2:B5"

' Series two contains sales growth data for 1999.
ChartSpace1.Charts(0).SeriesCollection(1).SetData chConstants.chDimSeriesNames, chConstants.chDataBound, "C1"
ChartSpace1.Charts(0).SeriesCollection(1).SetData chConstants.chDimCategories, chConstants.chDataBound, "A2:A5"
ChartSpace1.Charts(0).SeriesCollection(1).SetData chConstants.chDimValues, chConstants.chDataBound, "C2:C5"

' Series two contains sales growth data for 2000.
ChartSpace1.Charts(0).SeriesCollection(2).SetData chConstants.chDimSeriesNames, chConstants.chDataBound, "D1"
ChartSpace1.Charts(0).SeriesCollection(2).SetData chConstants.chDimCategories, chConstants.chDataBound, "A2:A5"
ChartSpace1.Charts(0).SeriesCollection(2).SetData chConstants.chDimValues, chConstants.chDataBound, "D2:D5"

' Make the chart legend visible, format the left value axis as percentage,
' and specify that value gridlines are at 10% intervals.
ChartSpace1.Charts(0).HasLegend = True
ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).NumberForma t = "0%"
ChartSpace1.Charts(0).Axes(chConstants.chAxisPositionLeft).MajorUnit = 0.1
End Sub


if anyone has any idea about my problem i'd really appreciate it.


thanks




Please post Excel questions, in the Excel forum.

Please use the .. tags when you post your code. Edit or reply to this post to see how.

Thank you.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum