-1

Hey all i am trying to populate an array like so:

Dim tmpArray As String = ""

Do Until x = Form1.arrayCal.Length
    tmpArray = tmpArray & "," & x
    x += 1
Loop

tmpArray = Replace(tmpArray, ",1", "1")

Dim arrDaysInMonth As String() = {tmpArray}

Dim arrNumOfVisits As Double() = {10, 20, 30, 40, 50, 52, 20, 20, 10, 35, 3, 8, 47, 7, 2, 5, 55, 8, 0, 0, 6, 55, 0, 2, 12, 0, 0, 21, 14, 0, 3}

    Me.ChartControl1.Series.Clear()
    Dim s As New DataDynamics.ActiveReports.Chart.Series()

    s.Type = DataDynamics.ActiveReports.Chart.ChartType.Bar2D
    s.Points.DataBindXY(arrDaysInMonth, arrNumOfVisits)

However, it does not seem like i can do it that way.. Doing it this way seems to put it only in a 1D array and not {1,2,3,4,5...} type of array as it needs to be in.

Any help would be great!

David

StealthRT
  • 10,108
  • 40
  • 183
  • 342

2 Answers2

1

I think what you want can be accomplished by this:

    Dim daysCount As Integer = 31
    Dim arrDaysInMonth As String() = New String(daysCount - 1) {}

    For index As Integer = 0 To arrDaysInMonth.Length - 1
        arrDaysInMonth(index) = (index + 1).ToString()
    Next

    ' arrDaysInMonth(0) = "1"
    ' arrDaysInMonth(1) = "2"
    ' ...

Or maybe you want this:

    Dim arrayCal As String = "1,2,3,4,5,6"
    Dim tmpArray As String() = arrayCal.Split(","c)

    ' tmpArray(0) = "1"
    ' tmpArray(1) = "2"
    ' ...
John Alexiou
  • 28,472
  • 11
  • 77
  • 133
0

I suggest not to use an array if you want to create it dynamically, you should use collections as they are much quicker and they are saving resources:

Dim array As New System.Collections.ArrayList

Do Until x = Form1.arrayCal.Length
   array.Add(x)
   x += 1
Loop

You can also access the elements of the ArrayList by index.

By the way: your version is not working, because you would need to compile and run your code that it is working.

This

Dim arrDaysInMonth() As String = {"1,2,3"}

is not the same like this

Dim arrDaysInMonth() As String = {"1","2","3"}
Philipp
  • 1,425
  • 1
  • 11
  • 23