あなたの作りたいプログラムとは少し違いますが…。
VisualBasic2005で動作確認しました。
tenki.txt(C:\に置いて)
Monday,晴,南西,12,88,66
Tuesday,晴曇,南,3,90,77
Wednesday,曇,南東,6,88,56
Thursday,雪,北,15,66,44
Friday,雨,北東,12,70,55
Saturday,雷,東,9,72,56
Sunday,快晴,西,10,77,69
'-----------------------------------------
'Form1.vbに記述
Public Class Form1
Private pstrLine(6) As String
Private pstrState() As String = {"状態", "風向き", "風速", "最高気温", "最低気温"}
Private pstrday() As String = {"月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日", "日曜日"}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strPath As String = "C:\tenki.txt" 'とりあえず絶対パスで
Dim sr As New System.IO.StreamReader(strPath, System.Text.Encoding.Default)
For i As Integer = 0 To pstrLine.Length - 1
pstrLine(i) = sr.ReadLine() '一行ずつ読み込んで配列に入れる
Next
sr.Close()
'メニュー作成
Dim menu As New MenuStrip
Dim menuday As New ToolStripMenuItem("曜日")
For d As Integer = 0 To pstrday.Length - 1
Dim menudayItem As New ToolStripMenuItem(pstrday(d))
AddHandler menudayItem.Click, AddressOf dayClick
menuday.DropDownItems.Add(menudayItem)
Next
menu.Items.Add(menuday)
Me.Controls.Add(menu)
End Sub
Private Sub dayClick(ByVal sender As Object, ByVal e As EventArgs)
Dim strday As String = sender.ToString()
Dim intIdx As Integer = 0
Dim strData() As String
Dim strMsg As String = ""
Try
'どの曜日を押したか判断
For i As Integer = 0 To pstrLine.Length - 1
If pstrday(i) = strday Then
intIdx = i
Exit For
End If
Next
'押された曜日のデータを,で区切りで配列に入れる
strData = Split(pstrLine(intIdx), ",")
'表示する
For s As Integer = 0 To pstrState.Length - 1
strMsg &= pstrState(s) & "=" & strData(s + 1) & vbCrLf
Next
MsgBox(strMsg)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
お礼
わざわざこんなに詳しく書いていただいてホントにありがとうございました!! これで一番知りたいところがわかりました☆ 何とかやっていけそうです!