Windows7 にVisual Studio Express 2015 をインストールしりようしています。
フォームを開くと10行のテキストデータの読み込み1行ずつに分割してそれぞれの変数に格納し、LabelのTextにそれぞれを表示させたく下記のように書きました。
しかし、変数が未割り当てのローカル変数となりました動きません(エラーコード:CS0165)
どのようにしたら希望の表示がされるのかよろしくおねがいします。
using System;
using System.Text;
using System.Windows.Forms;
using System.IO ; // for StreamReader
using System.Text.RegularExpressions; // for Regex
namespace GameEdter
{
public partial class Form_State : Form
{
public Form_State()
{
InitializeComponent();
}
private void Form_State_Load(object sender, EventArgs e)
{
string _File = @"./dat.txt";
string st_name;
string st_lv;
string st_str;
string st_agi;
string st_dex;
string st_vit;
string st_int;
string st_min;
string st_luk;
string st_type;
string text = File.ReadAllText(_File, Encoding.Default);
Match match = Regex.Match(text, "\n(.+)");
if (match.Success)
{
st_name = text.Substring(0, match.Index + 1); // 行末の改行コードも含める
st_lv = text.Substring(1,match.Index + 1);
st_str = text.Substring(2,match.Index + 1);
st_agi = text.Substring(3,match.Index + 1);
st_dex = text.Substring(4,match.Index + 1);
st_vit = text.Substring(5,match.Index + 1);
st_int = text.Substring(6,match.Index + 1);
st_min = text.Substring(7,match.Index + 1);
st_luk = text.Substring(8,match.Index + 1);
st_type = text.Substring(9,match.Index + 1);
}
label_name.Text = st_name;
label_lv.Text = st_lv;
}
}
}