SubIndex が特定の値にマップされない場合は、if または switch を使用します。
これがifの方法です。
if(this.Index == 1100) {
if (this.SubIndex==1) putValue(Com_stMECUErr, this.Data);
if (this.SubIndex==2) putValue(B_sbbvk, this.Data);
if (this.SubIndex==3) putValue(Com_bMSVIdle,this.Data);
// 100's more if's
} else { //if this.Index != 1100
}
これが切り替え方法です。
if(this.Index == 1100) {
switch(this.SubIndex) {
case 1: putValue(Com_stMECUErr, this.Data); break;
case 2: putValue(B_sbbvk, this.Data); break;
case 3: putValue(Com_bMSVIdle,this.Data); break;
// 100's more cases
default: break;
}
// 100's more if's
} else { //if this.Index != 1100
}
SubIndex が特定の値にマップされる場合は、配列を使用して最短の方法で行うことができます。
YourDataType values[] = {
whatever,
Com_stMECUErr,
B_sbbvk,
Com_bMSVIdle,
hundredsmore
}
if(this.Index == 1100) {
putValue(values[this.SubIndex], this.Data);
}