I am Having Problem to Convert this Crystal Report formula in SSRS Expression Can Anyone Help me?
Formula 1:
Dim fromExDay as String
Dim toExDay as String
Dim sYr as String
Dim sMonth as String
Dim sDay as String
fromExDay = ToText({wk_TORIO0460_a.HktrExchngDayFrom})
fromExDay = Replace (fromExDay, ",", "" )
fromExDay = Replace (fromExDay, ".", "" )
toExDay = ToText({wk_TORIO0460_a.HktrExchngDayTo})
toExDay = Replace (toExDay, ",", "" )
toExDay = Replace (toExDay, ".", "" )
if Len (Trim(fromExDay)) > 0 and Len (Trim(toExDay)) > 0 then
sYr = Right(Left(fromExDay, 4),2)
if sYr <> "99" then
sYr = LEFT(CStr(CDbl(sYr) + 12),2)
end if
sMonth = Mid(fromExDay, 5, 2)
sDay = Left(Right(fromExDay, 4),2)
'fromExDay = sYr + sMonth + sDay
fromExDay = sYr + sMonth + sDay
sYr = Right(Left(toExDay, 4),2)
if sYr <> "99" then
sYr = LEFT(CStr(CDbl(sYr) + 12),2)
end if
sMonth = Mid(toExDay, 5, 2)
sDay = Left(Right(toExDay, 4),2)
toExDay = sYr + sMonth + sDay
'toExDay = Right(fromExDay, 2)
Formula = fromExDay + " ~ " + toExDay
Else
Formula = ""
End If
Value of ExchangeFrom and ExchangeTO is coming from Database . ExchangeFrom value = 20031031 ExchangeTo value = 200 Is There in Database
Is the return value supposed to be
151010 ~ 1220
There actually weren't many changes needed to convert it to an SSRS VB function. In SSRS, the function doesn't work directly with the field so you need to pass them to the function as parameters. Most of the rest of the VB in your old function should work the same in SSRS - I just removed the ToText functions that aren't in SSRS.
When you call the function from your text box, you pass the fields.
=code.Formula1(Fields!HktrExchngDayFrom.Value, Fields!HktrExchngDayTo.Value)
And here's the function:
Public Function Formula1(ByVal fromExDay as String, ByVal toExDay as String) as String
Dim sYr as String
Dim sMonth as String
Dim sDay as String
fromExDay = Replace (fromExDay, ",", "" )
fromExDay = Replace (fromExDay, ".", "" )
toExDay = Replace (toExDay, ",", "" )
toExDay = Replace (toExDay, ".", "" )
if Len (Trim(fromExDay)) > 0 and Len (Trim(toExDay)) > 0 then
sYr = Right(Left(fromExDay, 4),2)
if sYr <> "99" then
sYr = LEFT(CStr(CDbl(sYr) + 12), 2)
end if
sMonth = Mid(fromExDay, 5, 2)
sDay = Left(Right(fromExDay, 4), 2)
fromExDay = sYr + sMonth + sDay
sYr = Right(Left(toExDay, 4), 2)
if sYr <> "99" then
sYr = LEFT(CStr(CDbl(sYr) + 12), 2)
end if
sMonth = Mid(toExDay, 5, 2)
sDay = Left(Right(toExDay, 4), 2)
toExDay = sYr + sMonth + sDay
Formula1 = fromExDay + " ~ " + toExDay
Else
Formula1 = ""
End If
End Function
I think the sDay calculations are incorrect.
sDay = Left(Right(fromExDay, 4),2)
Seems to be getting the month again. It should probably be
sDay = Right(fromExDay, 2)
or, if it can be a longer string use MID:
sDay = Mid(fromExDay, 7, 2)
Which changes the result to:
151031 ~ 12