2017-09-22 7 views
-1

私のコードは3行のうち最も高い値をとり、それを「行」プロパティに追加する必要があります。しかし、それは私が期待していた動作をしていない、私はそれが行のマージとテキストの重複の結果、間違った値を追加すると仮定3行すべてでエラーが発生している。備考線よりも高い場合3つの値のうち最も高い値を決定し、その値を追加してください

item_title_lines値が追加されるべきであると発言線よりも高い場合にはitem_remark_lines

1を超える値は、追加されるべきだと両方の値が同じである場合、それは1以上ですか。

unit_lines 2.これの最大値は唯一の両方の値が1

If item_title_lines > item_remark_lines And item_title_lines > 1 Then line = line + item_title_lines 
If item_remark_lines > item_title_lines And item_remark_lines > 1 Then line = line + item_remark_lines 
If item_remark_lines = item_title_lines Then line = line + item_remark_lines 
     End If 
     End If 
If item_remark_lines = 1 And item_title_lines = 1 Then 
     line = line + unit_lines 
     End If 
であれば追加されました

私が試したこれのもう一つの変化は、同じ結果を達成

If Math.Max(item_title_lines, item_remark_lines) >= unit_lines Then 
       line = line + Math.Max(item_title_lines, item_remark_lines) 'Add highest of those values to line count 
       Else 
       line = line + unit_lines 'Otherwise, add unit lines to line count 
       End If 

です。 3つの値を比較して最高値を加えるよりエレガントな方法がありますか?

+1

を。 – jmcilhinney

答えて

1

私はこの1つが好き:ちょうど配列にすべての値を入れ、その上に `Max`を呼び出す

line += {item_title_lines, item_remark_lines, unit_lines}.Max() 
+0

これはC#で、vb.netではなく – jeroenh

+0

これはvb.netで問題なく動作します。少なくともvs2017では –

+0

@jeroenhが間違っています。これはVB – Jaxi

関連する問題