Codey McCodeface Codey McCodeface - 6 months ago 24 Question

determine which of 3 values is highest and add it's value

My code needs to take the highest value of 3 lines and add it to the "line" property. However it's not behaving how I would expect, I'm having erroneous errors in all 3 lines where I assume it adds the wrong values, resulting in line merging and text overlapping.

value should be added if higher than remark lines and it's over 1

value should be added if higher than remark lines and it's over 1, or if both values are the same

has a max value of 2. This is only added if both values are 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

Another variation of this I've tried is

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
line = line + unit_lines 'Otherwise, add unit lines to line count
End If

Which achieves the same results. Is there a more elegant way of comparing 3 values and adding the highest?

Answer Source

I like this one:

line += {item_title_lines, item_remark_lines, unit_lines}.Max()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download