July 21, 2008 at 8:33 am
I have the following code added to the Code tab in the Report properties:
Public Function FMTDT(ByVal DTS As DateTime) As String
Dim Result As String, HR as Integer
Result = ""
HR = ""
If Month(DTS)<10 Then
Result = "0" & Month(DTS) & "/"
Else
Result = Month(DTS) & "/"
End If
If Day(DTS)<10 Then
Result = Result & "0" & Day(DTS) & "/"
Else
Result = Result & Day(DTS) & "/"
End If
Result = Result & CStr(Year(DTS)) & " "
If Hour(DTS) = 0 Then
Result = Result & "12:"
Else
If Hour(DTS)>12 Then
HR = Hour(DTS) - 12
Else
HR = Hour(DTS)
End If
If HR<10 Then
Result = Result & "0" & HR & ":"
Else
Result = Result & HR & ":"
End If
End If
If Minute(DTS)<10 Then
Result = Result & "0" & Minute(DTS) & ":"
Else
Result = Result & Minute(DTS) & ":"
End If
If Second(DTS)<10 Then
Result = Result & "0" & Second(DTS) & " "
Else
Result = Result & Second(DTS) & " "
End If
If Hour(DTS)>11 Then
Result = Result & "PM"
Else
Result = Result & "AM"
End If
Return Result
End Function
I don't know if I need any additional references, as BOL indicates that Report Server adds a couple automatically. The problem I'm having is that previewing the report shows #Error for the textbox that points to this function, and in editing the expression, the FMTDT part of:
=Code.FMTDT(Fields!DatePended.Value)
gets a squiggly red underline. As I'm brand new to SSRS, I need some help here on what I'm sure I haven't done correctly. Thanks!
Steve
(aka smunson)
:):):)
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
July 21, 2008 at 9:00 am
Well, for this purpose, I finally figured out how to overcome the formatting problem using the Format string, so now I don't need this particular solution, however... I sure would like to know why it didn't work. I may need something some day soon and will need to know how to get such code to work.
Steve
(aka smunson)
:):):)
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
July 21, 2008 at 9:16 am
This line:
HR = ""
is causing .NET to throw an "Conversion from String to Integer" error. The way you are referencing the code in the report is fine. The squiggly line in the expression dialogue will be there for any custom code.
BTW-this is why most people recommend creating and testing custom code using the real VB environment.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
July 21, 2008 at 9:23 am
That figures. Just when I figure out that I didn't need HR as a string, and instead needed it as a number, I forget to remove the initialization code. Boy am I glad I can count on an extra set of eyes from this forum. Thanks Jack!!!
Steve
(aka smunson)
:):):)
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply