0

i am using following code to display chart records from Listview1

Dim X(1 To 5, 1 To 2) As Variant

Dim i As Integer, j As Integer
 j = 1
 For i = 1 To Listview1.ListItems.Count
 X(j, 1) = Listview1.ListItems(i).Text
 X(j, 2) = Listview1.ListItems(i).SubItems(1)
 j = j + 1
 Next i

MSChart1.ChartData = X
MSChart1.chartType = 1

I need something like :

Dim X(1 To Listview1.listitems.count, 1 To 2) As Variant

it will help to add rows in mschart control

2
  • Do you get an error when you declare the array like that? I'm not sure what the issue is. Just as a side point I don't think you need the i either you could do it all using j. Commented Feb 9, 2016 at 9:09
  • Error while declaring as above : 'require constant' Commented Feb 9, 2016 at 9:27

1 Answer 1

2

Dim with an array requires the dimension argument to be constant (resolvable at compile time), you attempt to use a variable.

To use a variable, declare an undimensioned array:

Dim X() as variant

Then define its length with ReDim:

ReDim X(1 To Listview1.listitems.count, 1 To 2) '// no type

Or you can simply:

ReDim X(1 To Listview1.listitems.count, 1 To 2) as variant
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.