Reportviewer VB.NET about Switch Expression

江枫思渺然 提交于 2019-12-11 17:17:52

问题


Hello everyone can anyone correct my codes in rdlc tables

i have 1 tables and on that table there was a Field!ans1 that was computing for the average of the column(RED CIRCLE in IMAGE) then i want that average to filter to an if statement to identify if that average is Agree , disagree or Stronglyagree(BLACK CIRCLE IN THE IMAGE)

Here's the Picture of my RDLC Table the Black Circle is the If Statement that will identify if the Average Below in the Red Circle if is Agree,Disagree,or Strongly Agree but i am having a problem because the statement always stock on Disagree even its value is 3

// Here is my Code in the Black Circle in the IMAGE
=Switch(Fields!ans1.Value < 1, "Strongly Disagree ",
Fields!ans1.Value > 2, " Disagree",
Fields!ans1.Value > 3, "Agree",
Fields!ans1.Value > 4, "Strongly Agree"
)

//Here is the Code in the RedCircle 
=Avg(CDbl(Fields!ans1.Value))

回答1:


Remember that a switch statement of any kind is evaluated top-down. Is 3.00 greater than 2? Yes it is, so the result is " Disagree" (why you haven't noticed and removed that rogue space, I don't know). If you are going to compare using the 'greater than' operator then you need to compare the largest value first this:

=Switch(Fields!ans1.Value < 1, "Strongly Disagree",
Fields!ans1.Value > 4, "Strongly Agree",
Fields!ans1.Value > 3, "Agree",
Fields!ans1.Value > 2, "Disagree"
)

should work. That's just basic logic that you should have learned in maths class. Note that I have removed that rogue space too.

By the way, that is still going to ignore any values in the range 1.0 - 2.0.



来源:https://stackoverflow.com/questions/52133770/reportviewer-vb-net-about-switch-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!