Friday, March 23, 2012

frustrating formats

there are times i realize why people are resistant to .net...
in vb6, i can use: format$(fields!phonenumber,"(###) ###-####")
in vbnet:
1 - problem: no support for string formatting, only numbers
compensate: use csng
result: format(csng(fields!phonenumber),"(###) ###-####")
2 - new problem: empty strings result in an error
compensate: use iif function
result: iif ( len(trim(fields!phonenumber))=0,"",
format(csng(fields!phonenumber),"(###) ###-####"))
3 - new problem: vbnet evaluates ALL THREE EXPRESSIONS, regardless of the
condition. so empty strings still result in an error.
this is inexplicable.
iif(<condition>,<truepart>,<falsepart>) replaces:
if <condition> then
<truepart>
else
<falsepart>
end if
why are all 3 being evaluated?
so, half an hour later, i have no solution.
simple need: i want to display a phone number properly formatted if one
exists, and nothing if it doesn't.
please help!
dushan bilbijaTry an expression like this.
=iif(Fields!phonenumber.Value = Nothing, "",
format(csng(fields!phonenumber.Value),"(###) ###-####"))
Bruce Johnson [MSFT]
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Dushan Bilbija" <dbilbija@.msn.com> wrote in message
news:uBwTRH0iEHA.2664@.TK2MSFTNGP11.phx.gbl...
> there are times i realize why people are resistant to .net...
> in vb6, i can use: format$(fields!phonenumber,"(###) ###-####")
> in vbnet:
> 1 - problem: no support for string formatting, only numbers
> compensate: use csng
> result: format(csng(fields!phonenumber),"(###) ###-####")
> 2 - new problem: empty strings result in an error
> compensate: use iif function
> result: iif ( len(trim(fields!phonenumber))=0,"",
> format(csng(fields!phonenumber),"(###) ###-####"))
> 3 - new problem: vbnet evaluates ALL THREE EXPRESSIONS, regardless of the
> condition. so empty strings still result in an error.
> this is inexplicable.
> iif(<condition>,<truepart>,<falsepart>) replaces:
> if <condition> then
> <truepart>
> else
> <falsepart>
> end if
> why are all 3 being evaluated?
> so, half an hour later, i have no solution.
> simple need: i want to display a phone number properly formatted if one
> exists, and nothing if it doesn't.
> please help!
> dushan bilbija
>

No comments:

Post a Comment