-1

嘿,我正在尝试像这样填充数组:

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)

但是,我似乎不能那样做..这样做似乎只将​​它放在一维数组中,而不是 {1,2,3,4,5...} 类型的数组,因为它需要将在。

任何帮助都会很棒!

大卫

4

2 回答 2

1

我认为您想要的可以通过以下方式完成:

    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"
    ' ...

或者,也许你想要这个:

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

    ' tmpArray(0) = "1"
    ' tmpArray(1) = "2"
    ' ...
于 2012-04-17T00:00:51.007 回答
0

如果要动态创建数组,我建议不要使用数组,应该使用集合,因为它们更快并且节省资源:

Dim array As New System.Collections.ArrayList

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

您还可以通过索引访问 ArrayList 的元素。

顺便说一句:您的版本不工作,因为您需要编译和运行它正在工作的代码。

这个

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

不像这样

Dim arrDaysInMonth() As String = {"1","2","3"}
于 2012-04-16T23:36:41.873 回答