How to check multiple conditions in rdlc expression - reportviewer

I have worked on only possible 2 in rdlc Expression values as like
=iif((Fields!Gender.Value="1"),"Male","Female")
Here I can work with only 2 possibilities. But if I want to check 3 or more conditions than how can I?

Use the Switch if you have more conditions, it is also more readable.
=Switch(
Fields!Gender.Value = 1, "Male",
Fields!Gender.Value = 2, "Female"
)
rdlc expression iif use?

You can use the Code property of the report. Right-click a blank space outside your report and click Report Properties or click the Report menu and click report properties.
Click the "Code" tab and type your condition checking statement as below
Public Function GetGender(ByVal val as String) As String
Dim retVal as String = ""
If(val = "1")
retVal = "Male"
Else If (val = "2")
retVal = "???"
Else If (val = "3")
retVal = "???"
Else
retVal = "???"
End If
Return retVal
End Function
Then call the function in the expression of your textbox
= Code.GetGender(Fields!Gender.Value)

try this one :
=iif(Fields!Gender.Value="1","Male", iif(Fields!Gender.Value="2","Female","Undefined"))
the format is :
=iif(expression=value, true, false)
you can change with :
=iif(expression=value, true, iif(expression2=value2, true, false))

Switch and Custom Code look's nice, Thank you Guys
But if you insist using iif() condition then,
=iif( (Fields!Gender.Value="1"), "Male", iif( (Fields!Gender.Value="2"), "Female", "Something Else" ) )
Ok, Bye

Related

Comparing 2 Function String Results VB.Net

I have 2 separate functions, each one returns its own string value.
I am wanting to check that both return a specific string value and if they do then perform a task.
Example:
If function Apples returns "Apples" and Function Pears () returns "Pears" then do something
I am currently using 2 nested If statements and I want to know if this is the best way to do it.
If Apples() = "Apples" Then
If Pears() = "Pears" Then
"Do something here"
End If
End If
Using ANDALSO, if the first comparison fails, the second comparison is not made:
If String.Compare(Apples(),"Apples", True) = 0 ANDALSO String.Compare(Pears(),"Pears", True) = 0 Then
'Do Something Here
End If
Be careful with string comparisons, the comparison is case sensitive. "Apples" <> "APPLES".
Another version:
If Apples().ToUpper = "APPLES" ANDALSO Pears().ToUpper = "PEARS" Then
'Do Something Here
End If

Report Builder expression return string when SUM evaluates to false

I'm using Microsoft Report Builder to create a report that prints 900 school report cards. The only type of expression I can get working that returns the grade (from SQL query) is a SUM. But when SQL has a 0 I want to return/print a string that says "N/A" I understand SUM is looking for an integer, so I can only get it to return "0" or I can use "nothing" to get blank. Is there another expression, or can I convert the integer somehow? I tried using just IIF, but kept getting errors on too many conditions. Here is my expression...
=SUM(IIF(Fields!StudentPeriod.value = "2" And Fields!SkillFour.value > "0", Fields!SkillFour.value, nothing), "UserName")
There are two ways. You can warp around your expression another condition:
=IIF(SUM(IIF(Fields!StudentPeriod.value = "2" And Fields!SkillFour.value > "0", Fields!SkillFour.value, Nothing), "UserName") = Nothing, "N/A", SUM(IIF(Fields!StudentPeriod.value = "2" And Fields!SkillFour.value > "0", Fields!SkillFour.value, nothing), "UserName"))
Or you can go under the textbox properties Number > Currency and check the option Show value as -/(None).
Also, you should not use such an condition:
Fields!SkillFour.Value > "0"
This indicats that your value "0" is a string and you want to use a mathematical symbol > on a string. You should convert it to an integer or double with
CInt(Fields!SkillFour.Value) > 0

Access SQL > Select "Height" out of some text

I've got an Access Database filled with some product-informations.
unfortunately data like height, width etc. isn't in a separated column.
So I was wondering how I could use some SQL so I can filter/split those values.
For example it looks like this:
Table: SHP_PRODUCT
Field: SHORT_DSC
Value: Candle "Country", Height 120mm, Diameter 50mm, red
Result should be: "120mm"
Note: The height doesn't always have the same position like "It's the second word". Also I can't guarantee it's comma-separated.
How about using RegEx?
Public Function extractHeight(ByVal val as String) As String
Dim regEx As New VBScript_RegExp_55.RegExp
Dim regExMatches As Object
regEx.Pattern = "Height\s[\d*\,*\.*]+[a-z]{0,1}m"
regEx.Global = False
Set regExMatches = regEx.Execute(val)
If regExMatches.Count > 0 Then
extractHeight = Replace(regExMatches(0), "Height ", "")
Else
extractHeight = ""
End If
End Function
Use in query as aforementioned
The regex pattern Height\s[\d*\,*\.*]+[a-z]{0,1}m matches for a string that begins with "Height", followed by a space, then a number of whatever length with '.' or ',', then a string such as cm, mm, m.
Make sure to add Microsoft VBScript Regular Expressions 5.5 to References in the VBA edtior (Extras - References)
You can create small function to retrieve this:
Public Function ExtractHeight(ByVal Value As String) As String
Dim Parts As Variant
Parts = Split(Value, "Height")
If UBound(Parts) > LBound(Parts) Then
ExtractHeight = Replace(Trim(Split(Parts)(1), " ")(0)), "m,", "m")
End If
End Function
Then use that in your query:
Height: ExtractHeight([SHORT_DSC])

I'm not able to get the selected value from ContentControl and I'm not able also to set the value I want

I'm trying to make a dependent drop-down list where the user may select the first drop-down list and all the other dependent drop-down list will change automatically.
Select Case ContentControl.Title
Case "T1_1"
Select Case ContentControl.DropdownListEntries.Item.Value
Case "male"
ActiveDocument.SelectContentControlsByTitle("T1_2").Item(1).Value = "male"
ActiveDocument.SelectContentControlsByTitle("T1_3").Item(1).Value = "male"
ActiveDocument.SelectContentControlsByTitle("T1_4").Item(1).Value = "male"
Case "female"
ActiveDocument.SelectContentControlsByTitle("T1_2").Item(1).Value = "female"
ActiveDocument.SelectContentControlsByTitle("T1_3").Item(1).Value = "female"
ActiveDocument.SelectContentControlsByTitle("T1_4").Item(1).Value = "female"
End Select
I'm not able to get the selected value "male or female" and I'm not able also to set the value I want.
From what I looked up some time ago, Microsoft just forgot to let you query the selected value of a DropDown-ContentControl.
You can only get ContentControl.Range.Text, so if you need to look up the corresponding shorthand-value, you have to loop through:
Public Function getCCDD_value(cc As ContentControl) As String
getCCDD_value = ""
For Each Item In cc.DropdownListEntries
If Item.Text = cc.Range.Text Then
getCCDD_value = Item.Value
End If
Next
End Function
For changing, you can simply set the ContentControl's .Range.Text. It must match an existing dropdown-listentries-text (case sensitive) in order to return the correct value afterwards.
Although it may seem like "extra work", if you are in a position to map your content control to a Custom XML Part, you can get the value directly from the mapping.
As an example (you would have to work somewhat harder to do this correctly), starting with a new document:
Sub insertTestDDLCCandCXP()
Dim cc As Word.ContentControl
Dim l As Long
Dim sCXP As String
For l = ActiveDocument.CustomXMLParts.Count To 4 Step -1
ActiveDocument.CustomXMLParts(l).Delete
Next l
sCXP = "<?xml version='1.0' encoding='utf-8'?><ccData xmlns='bibadia1'><ccDDL1Value/></ccData>"
With ActiveDocument
' add a part
.CustomXMLParts.Add sCXP
' clear out the document
.Range.Delete
Set cc = .ContentControls.Add(wdContentControlDropdownList)
With cc
.DropdownListEntries.Add "dt1", "val1"
.DropdownListEntries.Add "dt2", "val2"
.DropdownListEntries.Add "dt3", "val3"
' using "ns0" is a kludge - you should determine the namespace that
' Word wants to use
.XMLMapping.SetMapping ("//ns0:ccData/ns0:ccDDL1Value")
End With
End With
End Sub
You can then retrieve the Value using (again for example)
activedocument.ContentControls(1).XMLMapping.CustomXMLNode.Text
Answer #1 seems to be the right one. Here's the VSTO C# version that gives you the .Value. You can get the ordinal position with .Index. Returns null for no or mismatched selection.
var currentChoice = cc.DropdownListEntries.Cast<ContentControlListEntry>()
.FirstOrDefault(cl => cl.Text == cc.Range.Text)
?.Value;

String Comparison with Array Item and String with VBA in Excel

This is probably a simple one, but I can't seem to find out what's wrong:
if temp_array(1) = temp_string2 & temp_array(2) = "w" then
....
end if
the values are:
temp_array(1) = "test1"
temp_string2 = "test2"
temp_array(2) = "w"
I get a type mismatch error highlighting the conditional comparisons...
& is string concatenation, not logical and.
if temp_array(1) = temp_string2 And temp_array(2) = "w" then