2013-10-04 85 views
1

我一直在爲學校編寫一個電影搜索的東西,我遇到了這個問題,我不知道如何解決它。類型'一維數組的字符串'的值不能轉換爲'字符串'

While Not FilmSearcher.EndOfData   'loop until end of file 
    currentRow = FilmSearcher.ReadFields() 'read in the fields of each line 
    For j = 0 To 3 
     Films(i, j) = currentRow(j)  'put the fields into film array 
    Next 

    i = i + 1 
End While 

currentRow = FilmSearcher.ReadFields()是不工作

+1

顯示filmsearch.readfields代碼。 – Tarik

回答

6

的一部分。如果錯誤信息是在您的標題,那麼我敢打賭,你已經宣佈currentRow作爲

Dim currentRow As String 

,而不是你需要將其聲明爲一維數組

Dim currentRow() as String 
0

currentRow變量未被正確聲明。取而代之的是:

Dim currentRow As String 

你需要其中之一:

Dim currentRow() As String 
Dim currentRow As String() 

你選擇哪一個是優先考慮的問題。他們的意思是一樣的。您還可以完全避免這個變量:

While Not FilmSearcher.EndOfData   
    'read in the fields of each line and put into film array 
    Films(i) = FilmSearcher.ReadFields()   
    i = i + 1 
End While 
0

就我而言,我宣佈我的方法不正確地返回一個數組:

Function GetById(ByVal id As Integer) As String 

和語法應該是:

Function GetById(ByVal id As Integer) As String() 

而我可以返回一串字符串:

Dim arrayOfStrings() As String 
arrayOfStrings = {"John", "Josh", "Jason", "Jill", "Kunta Kinte"} 
Return arrayOfStrings 
相關問題