I am trying to import an Excel csv file into MSChart. The file is a single column (A) comprised of general cell data, which are all numbers, like this for 1250 points:
A
1 2
2 4
3 17
4 86
5 102
6 125
etc.
This code keeps saying iData is subscript out of range. What am I doing wrong?
Private Sub CmdOpenFile_Click()
With CommonDialog1
On Error Resume Next
.Flags = cdlOFNOverwritePrompt
.DialogTitle = "Open file..."
.Filter = "CSV Files (*.csv) | *.csv"
.ShowOpen
OpenName = .FileName
End With
Set tempfile = fso2.OpenTextFile(Drive1.Drive & "\OpenName", ForReading)
Debug.Print tempfile
Debug.Print OpenName
Dim iData() As String
Dim inum As Integer
inum = 0
Open OpenName For Input As #1
Debug.Print OpenName
Do While Not EOF(1)
ReDim Preserve iData(inum)
Input #1, iData(inum)
inum = inum + 1
Debug.Print iData(inum)
Loop
Close #1
With MSChart1
.chartType = VtChChartType2dLine
.RowCount = 1250
.ColumnCount = 2
.ChartData = Data
.TitleText = "GRAPH"
.ChartData = iData
With .DataGrid
.SetSize 1, 1, 1250, 1 '(rowLabelCount, columnLabelCount, dataRowCount, columnLabelCount)
Dim intIndex As Integer '*******************
MSChart1.RowCount = 1250
End With
With .Plot
With .Axis(VtChAxisIdY).ValueScale
.Auto = False
.Minimum = 0
.Maximum = 625
End With
With .Axis(VtChAxisIdX).AxisGrid
.MajorPen.VtColor.Set 204, 204, 204
.MajorPen.Width = 2
.MinorPen.VtColor.Set 204, 204, 204
.MinorPen.Width = 2
End With
With .Axis(VtChAxisIdY).AxisGrid
.MajorPen.VtColor.Set 204, 204, 204
.MajorPen.Width = 2
.MinorPen.VtColor.Set 204, 204, 204
.MinorPen.Width = 2
End With
With .SeriesCollection
.Item(1).LegendText = "Data"
With .Item(1).DataPoints(-1) 'controls text for flow line - grid too small - can't see the text
.Brush.FillColor.Set 255, 0, 0 '# red line
End With
End With '#seriescoll
End With '# plot
End With
End Sub
Thanks,
norason
A
1 2
2 4
3 17
4 86
5 102
6 125
etc.
This code keeps saying iData is subscript out of range. What am I doing wrong?
Private Sub CmdOpenFile_Click()
With CommonDialog1
On Error Resume Next
.Flags = cdlOFNOverwritePrompt
.DialogTitle = "Open file..."
.Filter = "CSV Files (*.csv) | *.csv"
.ShowOpen
OpenName = .FileName
End With
Set tempfile = fso2.OpenTextFile(Drive1.Drive & "\OpenName", ForReading)
Debug.Print tempfile
Debug.Print OpenName
Dim iData() As String
Dim inum As Integer
inum = 0
Open OpenName For Input As #1
Debug.Print OpenName
Do While Not EOF(1)
ReDim Preserve iData(inum)
Input #1, iData(inum)
inum = inum + 1
Debug.Print iData(inum)
Loop
Close #1
With MSChart1
.chartType = VtChChartType2dLine
.RowCount = 1250
.ColumnCount = 2
.ChartData = Data
.TitleText = "GRAPH"
.ChartData = iData
With .DataGrid
.SetSize 1, 1, 1250, 1 '(rowLabelCount, columnLabelCount, dataRowCount, columnLabelCount)
Dim intIndex As Integer '*******************
MSChart1.RowCount = 1250
End With
With .Plot
With .Axis(VtChAxisIdY).ValueScale
.Auto = False
.Minimum = 0
.Maximum = 625
End With
With .Axis(VtChAxisIdX).AxisGrid
.MajorPen.VtColor.Set 204, 204, 204
.MajorPen.Width = 2
.MinorPen.VtColor.Set 204, 204, 204
.MinorPen.Width = 2
End With
With .Axis(VtChAxisIdY).AxisGrid
.MajorPen.VtColor.Set 204, 204, 204
.MajorPen.Width = 2
.MinorPen.VtColor.Set 204, 204, 204
.MinorPen.Width = 2
End With
With .SeriesCollection
.Item(1).LegendText = "Data"
With .Item(1).DataPoints(-1) 'controls text for flow line - grid too small - can't see the text
.Brush.FillColor.Set 255, 0, 0 '# red line
End With
End With '#seriescoll
End With '# plot
End With
End Sub
Thanks,
norason