2014-09-22 91 views
0

我試圖用for循環打印日期列表。我收到一個錯誤,說'AddDays'不是'System.Array'的成員。如何打印日期列表asp.net

Dim payDates(10) as Date 

    For index As Integer = 1 to 10 
     Redim Preserve payDates(index) 
     payDates(index) = payDates.AddDays(1) 
     index +=1 
    NEXT 

    Response.Write(payDates) 
+0

如答案中所述,該數組不是日期或日期時間對象,因此如果不首先引用索引就不能使用AddDays。 但我相信你在錯誤的軌道上,ReDim可能不是想要的。 你可以發表你想要什麼'Response.Write(payDates)'來顯示的例子嗎? – NiKiZe 2014-09-22 17:24:13

回答

2

我不是VB專家,但你需要訪問數組的索引,而不是該數組本身:

Dim payDates(10) as Date 

    For index As Integer = 1 to 10 
     Redim Preserve payDates(index) 
     payDates(index) = payDates(index).AddDays(1) 
     index +=1 
    NEXT 

    Response.Write(payDates) 

你也migzht想寫每次約會。在這種情況下,改變你的代碼如下:

Dim payDates(10) as Date 

    For index As Integer = 1 to 10 
     Redim Preserve payDates(index) 
     payDates(index) = payDates(index).AddDays(1) 
     Response.Write(payDates(index)) 
     index +=1 
    NEXT 

本質: payDates的類型是System.Array payDates(index)包含DateTime變量的位置索引,其中指數型int

0

好,AddDays在不是System.Array的成員。但是,您仍然試圖調用它:

payDates.AddDays(1) 

如果您試圖獲取修改日期,請引用數組的日期元素。事情是這樣的:

payDates(index).AddDays(1) 

(請注意,如果你正在尋找顯示網頁上的信息,這是一個很大更好地設置該頁面的元素,而不是使用Response.Write()的信息,你也沒有控制Response.Write()在結果頁面中發出其輸出的位置。)