-
Nov 17th, 2010, 08:21 PM
#1
Thread Starter
Frenzied Member
vb6 multidimentional array for mschart graph...
hi ya... lemme give you my code first... i will explain a little below
Code:
' note : hin.... and hout's etc r all constants in delcarations relating to integer values [made it easier to note :P]
Private Sub cmdPlotGraph_Click()
StatusBar1.Panels(1).Text = "Preparing data..."
Dim icnt As Integer
Dim aChartData(1, 1 To 14) As Variant
aChartData(1, 2) = "Unmatched Calls"
aChartData(1, 3) = "Arrival Auto"
aChartData(1, 4) = "Arrival Manual"
aChartData(1, 5) = "Arrival Missed"
aChartData(1, 6) = "Arrival Cancelled"
aChartData(1, 7) = "Arrival Delayed"
aChartData(1, 8) = "Arrival Callout"
aChartData(1, 9) = "Depart Auto"
aChartData(1, 10) = "Depart Manual"
aChartData(1, 11) = "Depart Missed"
aChartData(1, 12) = "Depart Cancelled"
aChartData(1, 13) = "Depart Delayed"
aChartData(1, 14) = "Depart Callout"
Dim li As ListItem
For Each li In Me.lvDetails.ListItems
For icnt = 1 To 14
ReDim Preserve aChartData(li.Index + 1, icnt)
Next icnt
aChartData(li.Index + 1, 1) = li.Text
aChartData(li.Index + 1, 2) = li.SubItems(hUnmatched - 1)
aChartData(li.Index + 1, 3) = li.SubItems(hInAuto - 1)
aChartData(li.Index + 1, 4) = li.SubItems(hInManual - 1)
aChartData(li.Index + 1, 5) = li.SubItems(hInMissed - 1)
aChartData(li.Index + 1, 6) = li.SubItems(hInCancel - 1)
aChartData(li.Index + 1, 7) = li.SubItems(hInDelay - 1)
aChartData(li.Index + 1, 8) = li.SubItems(hInCall - 1)
aChartData(li.Index + 1, 9) = li.SubItems(hOutAuto - 1)
aChartData(li.Index + 1, 10) = li.SubItems(hOutManual - 1)
aChartData(li.Index + 1, 11) = li.SubItems(hOutMissed - 1)
aChartData(li.Index + 1, 12) = li.SubItems(hOutCancel - 1)
aChartData(li.Index + 1, 13) = li.SubItems(hOutDelay - 1)
aChartData(li.Index + 1, 14) = li.SubItems(hOutCall - 1)
Next li
DoEvents
StatusBar1.Panels(1).Text = "Loading graph..."
Load frmChart
frmChart.MSChart1.ChartData = aChartData
StatusBar1.Panels(1).Text = "Showing graph..."
frmChart.Show vbModal, Me
StatusBar1.Panels(1).Text = Empty
End Sub
ok basically i have a list view - detailed view, listing dates with figures of monitored calls into a server... etc... now these dates will not be fixed periods...
so i need to graph all dates ... this part is what im stuck at... when i come to redim the array it says the array dimentions are already set... how do i get arround this?: im guessing ive messed up somewhere...?
been a while since i last did some coding. so maybe its a simple error? [i hope] lol first time using this control too.. but i have figured the control [i think] its just loading this data into the array...
cheers guys.
Last edited by wpearsall; Nov 17th, 2010 at 08:25 PM.
Wayne
-
Nov 18th, 2010, 03:30 AM
#2
Re: vb6 multidimentional array for mschart graph...
You can only ReDim Dynamic arrays, ie those defined like, for example, this
Code:
Dim myArray () as Variant
Then before you use it you can set the 'initial dimensions' eg
Code:
ReDim myArray(1, 1 To 14)
(ie a 2 X 14 Array - Assuming you're not using 'Option Base 1')
To add elements:
Code:
ReDim Preserve myArray(1, 1 To 20)
Note that you can ony change the last dimension, so
Code:
ReDim Preserve myArray(2, 1 To 14)
will not work.
The use of 'Preserve' ensures that the values of existing elements are retained. If you don't use 'Preserve' all existing elements are cleared to default values when you ReDim.
For completeness, to obtain the Upper and Lower Bounds
Code:
intUpperA = UBound(myArray, 1)
intUpperB = UBound(myArray, 2)
intLowerA = LBound(myArray, 1)
intLowerB = LBound(myArray, 2)
intLowerA and intUpperA are the lower and upper bounds of the first dimesion
intLowerB and intUpperB are the lower and upper bounds of the second dimension
Last edited by Doogle; Nov 18th, 2010 at 02:36 PM.
-
Nov 19th, 2010, 04:22 AM
#3
Thread Starter
Frenzied Member
Re: vb6 multidimentional array for mschart graph...
cheers. ill check that out in a bit.
-
Nov 20th, 2010, 06:35 AM
#4
Thread Starter
Frenzied Member
Re: vb6 multidimentional array for mschart graph...
ok just checked it out, and its comin up with subscript out of range( error nine)
Code:
Dim li As ListItem
For Each li In Me.lvDetails.ListItems
'For icnt = 0 To 14
' ReDim Preserve achartdata(li.Index + 1, icnt)
'Next icnt
ReDim Preserve achartdata(li.Index + 1, 1 To 14) ' at this line in the code....
any idea's?
cheers.
- edit, its on li.index = 1 thats throwing the error, so its the first pass... should basically be running
Code:
ReDim Preserve achartdata(2, 1 To 14) ' at this line in the code....
the achartdata(1,1 to 14 ) is all set with the header rows fine... this row throws the error subscript out of range...?
Last edited by wpearsall; Nov 20th, 2010 at 06:37 AM.
Reason: additional
Wayne
-
Nov 21st, 2010, 02:58 AM
#5
Re: vb6 multidimentional array for mschart graph...
You're attempting to ReDim both dimensions using Preserve - I did mention that you can only ReDim the last dimension.
-
Nov 21st, 2010, 09:08 PM
#6
Thread Starter
Frenzied Member
Re: vb6 multidimentional array for mschart graph...
ok.. not sure what that means?
basically i seem to have solved my issues though by:
Code:
Dim achartdata() As Variant
ReDim achartdata(1 To lvDetails.ListItems.Count + 1, 1 To 14)
maybe u could explain how that is different to
Code:
redim preseve achartdata(2, 1 to 14)
redim preseve achartdata(3, 1 to 14)
redim preseve achartdata(4, 1 to 14)
? or isnt it? ahh well at least its working now but for future reference and all. ta.
-
Nov 22nd, 2010, 03:37 AM
#7
Re: vb6 multidimentional array for mschart graph...
The difference is that you are not using the 'Preserve' keyword.
When using 'Preserve' you can only change the last dimension
Code:
Dim strArray()
ReDim strArray(2,10)
(the '2' is the first dimension, '10' is the last dimension)
so
Code:
ReDim Preserve strArray(3,10)
will produce a 'subscript out of range' error, because you're trying to retain the contents of the array and change the first dimension, whereas
Code:
ReDim strArray(3,10)
is quite ok since you're not attempting to save the existing contents of the array.
Code:
ReDim Preserve strArray(2,20)
is OK since you are changing the last Dimension.
Last edited by Doogle; Nov 22nd, 2010 at 03:43 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|