例として
test.txtに
VB2008
初心者
と2行のテキストファイルがあるとします
Function ReadFile() as Dictionary(Of String,String)
Dim FileName As String = DataPath & "\test.txt"
Dim Data As New Dictionary(Of String, String)
If IO.File.Exists(FileName) = False Then
MessageBox.Show(FileName & vbCrLf & "がありません", "警告", MessageBoxButtons.OK)
Return Data
Exit Function
End If
Dim TextFile As IO.StreamReader
Dim Line As String
Dim i As Integer
TextFile = New IO.StreamReader(FileName)
i = 0
Do While -1
Line = TextFile.ReadLine
Select Case i
Case 0
Data("Soft") = Line
Case 1
Data("Class") = Line
End Select
i = i + 1
If Line Is Nothing Then
Exit Do
End If
Loop
TextFile.Close()
Return Data
End Function
これまでが関数です
この
FunctionはDictionary を返すわけです
Dim Word as New Dictionary(Of String,String)
Word = ReadFile()
Msgbox( Word("Soft"))
MsgBox (Word("Class"))
'ここでファイルの2行目の 初心者とメッセージが出されます




