Need help with report expression - RDLC - visual-studio-2010

I have a column type int and I want to check the value to display string instead of the number.
I added this expression
=IIf(Fields!Categ.Value = 1, "First", "")
=IIf(Fields!Categ.Value = 2, "Second", "")
=IIf(Fields!Categ.Value = 3, "Third", "")
=IIf(Fields!Categ.Value = 4, "Fourth", "")
=IIf(Fields!Categ.Value = 5, "Fifth", "")
but it is not working.
How can I do it?

Can you try this?
=Switch(
Fields!Categ.Value = 1, "First",
Fields!Categ.Value = 2, "Second",
Fields!Categ.Value = 3, "Third",
Fields!Categ.Value = 4, "Fourth",
Fields!Categ.Value = 5, "Fifth",
Fields!Categ.Value > 5, "",
Fields!Categ.Value < 1, "",
)

I believe the values returned by the .value condition are strings so you could either have to cast them or do a string comparison.
String Comparison
=IIf(Fields!Categ.Value == "1", "First", "")
Int Cast
=IIf(Int.Parse(Fields!Categ.Value) == 1, "First", "")
Its been awhile since I have worked with RDLC.

To add embedded code to a report, use the Code tab of the Report Properties dialog box. The code block you create can contain multiple methods. Methods in embedded code must be written in Microsoft Visual Basic and must be instance-based.
so for example:
public function getDescription(cat as integer) as string
dim sRet as string
select case cat
case 1: sRet = "first"
case 2: sRet = "second"
case else
sRet = "uh?"
end select
return sRet
end function
then use the expression:
=code.getDescription(fields!Categ.value)

Related

How can replace all case in value of column using linq.js?

I using linq.js and i want replace single quotes when searching data.
This my code.
var list = [
{ a: "50", b: 4, c: 1 },
{ a: "60", b: 3, c: 7 },
{ a: "'540'", b: 3, c: 3 }
];
var val = "'540'";
val = val.replace(/'/g, "&apos;");
var res = Enumerable.From(list).Where("($.a).replace(\"'\",\"&apos;\")=='" + val + "'").ToArray();
If there is only 1 single quote in the data, it works.
But if there are 2 single quote in it, it can't search.
Oh, linq.js the same code in javascript.
I have to use regex to replace:
It is ok , if i change to :
var res = Enumerable.From(list).Where("($.a).replace(\/'\/g,\"&apos;\")=='" + val + "'").ToArray();

Debugging generics in Lazarus IDE

I have this:
TDictionaryStrInt = specialize TFPGMap<string, integer>;
Can somebody tell me how the heck can I debug the Map, the Key/Value pairs?
I just see only reference to a memory address, but I really need to see the items.
Watch, local variables does not helps me.
I can see only this:
<TDictionaryStrStr> = {
<TFPSMAP> = {
<TFPSLIST> = {
<TOBJECT> = {
_vptr$ = {
0x5612ec,
0x230b988}},
FLIST = ,
FCOUNT = 1,
FCAPACITY = 4,
FITEMSIZE = 8},
FKEYSIZE = 4,
FDATASIZE = 4,
FDUPLICATES = DUPIGNORE,
FSORTED = false,
FONKEYPTRCOMPARE = $426b70 <TFPGMAP$2$CRC36DB32B4__KEYCOMPARE>,
FONDATAPTRCOMPARE = $523e30
<FGL$_$TFPSMAP_$__$$_BINARYCOMPAREDATA$POINTER$POINTER$$LONGINT>},
FONKEYCOMPARE = $0,
FONDATACOMPARE = $0}

Bad instruction error Swift 3 and XCode 8

I've been learning Swift 3 syntax lately and I thought that a good first project would be a Vigenère Cipher. So I've begun to create a script for it in Playground.
The issue is that I keep getting an error when I call the method and I know what the mistake is, it has to do with how I am calling my Dictionary value and the fact that I am unwrapping it, But I don't know what else to do about it. Any ideas?
import Foundation
let alphabet: [String: Int] = ["a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7, "i": 8,
"j": 9, "k": 10, "l": 11, "m": 12, "n": 13, "o": 14, "p": 15, "q": 16,
"r": 17, "s": 18,"t": 19, "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25]
let alphabet2: [Int: String] = [0: "a", 1: "b", 2: "c", 3: "d", 4: "e", 5: "f", 6: "g", 7: "h", 8: "i",
9: "j", 10: "k", 11: "l", 12: "m", 13: "n", 14: "o", 15: "p", 16: "q",
17: "r", 18: "s", 19: "t", 20: "u", 21: "v", 22: "w", 23: "x", 24: "y", 25: "z"]
var mess = "I once saw a big mosquito"
var key = "pass"
func cipher(message: String, key: String) -> String{
var code: [Int] = [] // will hold the encripted code
// removes whietspace from message and key
let trimmedMessage = message.trimmingCharacters(in: NSCharacterSet.whitespaces)
let trimmedKey = key.trimmingCharacters(in: NSCharacterSet.whitespaces)
// Sets the key the same size as the message
let paddedTrimmedKey = trimmedKey.padding(toLength: message.characters.count, withPad: trimmedKey, startingAt: 0)
// separates the message and key into individual characters
let charTrimmedMessage = Array(trimmedMessage.characters)
let charPaddedTrimmedKey = Array(paddedTrimmedKey.characters)
// Compare the values in the key to the message and scrambles the message.
var i = 0
for chr in charTrimmedMessage{
code.append((alphabet[String(chr)]! + alphabet[String(charPaddedTrimmedKey[i])]!) % 26) // <- I think the error comes from this line. Maybe the exclamation marks?
i += 1
}
var cyphr: String = "" // this will hold the return String
// I think I could have used some sort of "join" function here.
for number in code{
cyphr = cyphr + alphabet2[number + 1]!
}
return cyphr
}
cipher(message: mess, key: key) // <--- this returns an error, no clue why. The code works and compiles great.
I get this error:
If you could let me know any pointer on how to improve my code to avoid things like this even better.
Your alphabet dictionary does not have lookup values for the letters "I", " " which are contained in your plain text. The cipher function fails because of this (since it is force unwrapping an optional which is nil)
If you initialize the mess variable, you will get the cipher to work
var mess = "ioncesawabigmosquito"
cipher(...) -> "ypgvuttpqcbzcpljkjmh"
Either
update the alphabet lookup dictionary. E.g. add ' ' as a valid input, update alphabet2 to provide reverse lookup, and change the mod factor from 26 to 27 (to account for new ' ' character)
OR
validate your input beforehand. (trim spaces, replace spaces, convert uppercase to lowercase / strip characters not in valid range)
To trim your input to only include valid letters in the alphabet, you could try:
let validSet = CharacterSet.init(charactersIn: alphabet.keys.joined())
var messTrimmed = mess.trimmingCharacters(in: validSet.inverted)
Note that doing this mean losing information from the original message
Another bug:
The line cyphr = cyphr + alphabet2[number+1]! should be cyphr = cyphr + alphabet2[number]!.
It's not correct to add 1 to number since the values in the code array are computed mod 26, and the max key value in alphabet is 25. It will cause an exception when force unwrapping to a non-existent key.
E.g. try cipher(message: "ypgvuttpqcbzcpljkjmh", key: "pass") to make it fail.
Footnote
As a complete aside, here's a variant of the cipher function (I have not sanitized the inputs; just showing how the code could be written in a functional way)
func cipher2(message: String, key: String) -> String {
return
message
.characters
.enumerated()
.map { ($0, String($1)) }
.map {
(
alphabet[$1]!
+ alphabet[String(key[key.index(key.startIndex, offsetBy: ($0 % key.characters.count))])]!
) % 26
}
.map { alphabet2[$0]! }
.joined()
}

String permutations using recursion

For example if I have a string {a, b, c}. I need to print out on the console all the permutations without repeating letters from 1 letter to 3 letters like this:
a b c ab ac abc acb ba bc bac bca ca cb cab cba
How can I write this using recursion?
If you need all the permutations of the chars into a String you can use a recursive function.
Here's the code in Swift.
func visit(unused:[Character], used: [Character] = [Character]()) -> [String] {
var result = [String(used)]
for (index, char) in unused.enumerate() {
var unused = unused
unused.removeAtIndex(index)
var used = used
used.append(char)
result = result + visit(unused, used: used)
}
return result
}
As you can see the function receives 2 params:
unused: represents the list of chars not yet used
used: the chars used to build possible element of the ouput. This parameter is optional so if it's not passed to the function, an empty array is used (this is useful for the first invocation).
Test
let word = "abc"
let chars = [Character](word.characters)
print(visit(chars))
["", "a", "ab", "abc", "ac", "acb", "b", "ba", "bac", "bc", "bca", "c", "ca", "cab", "cb", "cba"]
Omitting the empty String
This results also contains the empty String but you can easily omit this value just update the function as shown below.
func visit(unused:[Character], used: [Character] = [Character]()) -> [String] {
var result = [String]()
if !used.isEmpty {
result.append(String(used))
}
for (index, char) in unused.enumerate() {
var unused = unused
unused.removeAtIndex(index)
var used = used
used.append(char)
result = result + visit(unused, used: used)
}
return result
}

Sorting a Table Containing Tables

I can sort a table with two pieces of information (the name and a second piece, such as age) with the following code:
t = {
Steve = 4,
Derek = 1,
Mike = 5,
Steph = 10,
Mary = 7,
Danny = 2
}
function pairsByKeys (t,f)
local a = {}
for x in pairs (t) do
a[#a + 1] = x
end
table.sort(a,f)
local i = 0
return function ()
i = i + 1
return a[i], t[a[i]]
end
end
for a,t in pairsByKeys (t) do
print (a,t)
end
Result:
Danny 2
Derek 1
Mary 7
Mike 5
Steph 10
Steve 4
I have a scenario where at a convention each person's name tag contains a barcode. This barcode, when scanned, enters four pieces of information about each person into a table database. This database is made up of the following pieces:
t = {
{name = "Mike", addr = "738 Rose Rd", age = 30, phone = "333-902-6543"}
{name = "Steph", addr = "1010 Mustang Dr", age = 28, phone = "555-842-0606"}
{name = "George", addr = "211 Glass St", age = 34, phone = "111-294-9903"}
}
But how would I change my code to sort all four entries (name, addr, age, phone) by age and keep all variables in line with one another?
I've been trying to experiment and am getting the hang of sorting a table by pairs and have a better idea how to perform table.sort. But now I want to take this another step.
Can I please receive some help from one of the programming gurus here?! It is greatly appreciated guys! Thanks!
You could use the age as the key of your table:
t = {
[30] = {name = "Mike", addr = "738 Rose Rd", age = 30, phone = "333-902-6543"},
[28] = {name = "Steph", addr = "1010 Mustang Dr", age = 28, phone = "555-842-0606"},
[34] = {name = "George", addr = "211 Glass St", age = 34, phone = "111-294-9903"},
}
function pairsByKeys (t,f)
local a = {}
for x in pairs (t) do
a[#a + 1] = x
end
table.sort(a,f)
local i = 0
return function ()
i = i + 1
return a[i], t[a[i]]
end
end
for a,t in pairsByKeys (t) do
print (t.name, t.addr, t.age, t.phone)
end
EDIT
Otherwise, if you don't want to change the structure of t, you could change your iterator generating function to keep track of the indexing:
t = {
{name = "Mike", addr = "738 Rose Rd", age = 30, phone = "333-902-6543"},
{name = "Steph", addr = "1010 Mustang Dr", age = 28, phone = "555-842-0606"},
{name = "George", addr = "211 Glass St", age = 34, phone = "111-294-9903"},
}
function pairsByAgeField(t,f)
local a = {}
local index = {}
for _, x in pairs(t) do
local age = x.age
a[#a + 1] = age
index[age] = x
end
table.sort(a,f)
local i = 0
return function ()
i = i + 1
return a[i], index[a[i]]
end
end
for a,t in pairsByAgeField(t) do
print (t.name, t.addr, t.age, t.phone)
end
Of course this makes pairsByAgeField less generally applicable than your original pairsByKeys (it assumes that the table being iterated has a given structure), but this is not a problem if you often have to deal with tables such as t in your application.

Resources