我一直在爲此苦苦掙扎了一段時間,經過廣泛的搜索後,我還沒有找到答案。通過特定的一組行和輸出數據搜索?
在我的Visual Basic類中,我有一個程序,我必須從文本文件(songs.txt)中獲取文本,在列表框中顯示流派,並在流派之後在組合框中顯示相應的歌曲顯示。
目前,這是我的代碼。
' Variables
Dim strFilePath As String = "E:\Advanced VB\DJPlayList\DJPlayList\songs.txt"
Dim strFileError As String = "File not found. Please try again."
Dim strFileErrorTitle As String = "File Error"
Dim objReader As IO.StreamReader
Dim intCount As Integer = 0
Dim strSongGenre(intCount) As String
Dim i As Integer = 0
' Finding the file
If IO.File.Exists(strFilePath) Then
' Opening the text file
objReader = IO.File.OpenText(strFilePath)
Do Until objReader.Peek = -1
ReDim Preserve strSongGenre(intCount)
strSongGenre(intCount) = objReader.ReadLine
cboMusicGenre.Items.Add(strSongGenre(intCount))
intCount += 1
Loop
Else
MsgBox(strFileError, , strFileErrorTitle)
Close()
End If
這增加了從文本文件中的所有信息到陣列中,並加載到列表框,但我被困在如何輸出流派的專門和與它對應的歌曲。
的文本文件,如下所示:
All You Need is Love-Beatles 'Song Name
Rock 'Song Genre
4.25 'Song Time
What Hurts the Most-Rascal Flatts
Country
5.25
Touch it-Busta Rhymes
Rap
5.46
My Girl-Temptations
R&B
4.35
What you know?-T.I.
Rap
4.30
如何具體得到流派和歌曲名稱?感謝您提前幫助
這不是VBA,它是VB.NET。我已經爲您更改了標籤......如果您需要幫助,則需要確保您解決了正確的受衆羣體問題。沒有人使用VBA可以幫助你做到這一點。 –
@Heinzi但在這種情況下,閱讀線條單獨適合需要什麼 –
@DavidWilson:採取的要點。 – Heinzi