中間処理はWHILE文を使う。
key="";
if (dorohaba=="1.5") {key3="1.5m未満";layerColor="53";}
if (dorohaba=="3.0") {key3="1.5m以上3.0m未満";layerColor="31";}
if (dorohaba=="5.5") {key3="3.0m以上5.5m未満";layerColor="30";}
if (dorohaba=="13") {key3="5.5m以上13.0m未満";layerColor="22";}
if (dorohaba=="25") {key3="13.0m以上";layerColor="14";}
if (dorohaba=="30") {key3="真幅道路等";layerColor="16";}
var ID=new String;;
var msg2;
var fukuin=dorohaba;
while (!dataFile.AtEndOfLine)
{
msg=dataFile.ReadLine();
while ( ( n1=msg.indexOf(key,0) ) == -1) {msg=dataFile.ReadLine();}
ID=msg.substring(n1+key.length+1,n1+key.length+14);
while ( ( n2=msg.indexOf("",0) ) == -1)
{msg=dataFile.ReadLine();}
n3=msg.indexOf("",0);
if (msg.substring(n2+8,n3) == key3 )
{
outMSG.WriteLine("-layer");
outMSG.WriteLine("M");
outMSG.WriteLine(ID);
msg2="C"+"\r\n";
msg2+=layerColor+"\r\n\r\n\r\n";
msg2+="dline\r\n";
msg2+="w\r\n";
msg2+=fukuin;
outMSG.WriteLine(msg2);
while ( ( n2=msg.indexOf("",0) ) == -1)
{msg=dataFile.ReadLine();}
n3=msg.indexOf("",0);
xy=msg.substring(n3+14,n3+37).split(" ");
xx=parseFloat(xy[0]);
yy=parseFloat(xy[1]);
ramu=xx/648000*PI;
phai=yy/648000*PI;
bl2xy();
msg2=yy+","+xx+",0.00";
outMSG.WriteLine(msg2);
while (true) {
msg=dataFile.ReadLine();
n3=msg.indexOf("",0);
if (n3==-1) {outMSG.WriteLine();break;}
xy=msg.substring(n3+14,n3+37).split(" ");
xx=parseFloat(xy[0]);
yy=parseFloat(xy[1]);
ramu=xx/648000*PI;
phai=yy/648000*PI;
bl2xy();
msg2=yy+","+xx+",0.00";
outMSG.WriteLine(msg2);
}
}
}
dataFile.Close();
outMSG.Close();
|
条件文( ! dataFile.AtEndOfStream) はファイルの最終行の時、真(true)。 !
で否定しているので、最終行までReadLine()が繰り返される仕組み。最終行になったら、
ループを抜け出し、ファイルをClose()してくれる。
WHILE文の条件判定はループの作業開始時点の判断。途中で最終行を飛び出すコード
を書くとエラー終了になる。途中に判定ルーチンでbreakさせることが必要。
ループの作業を一度してから判断するDOを使うのがいいのかも知れない。
|