|
-
Apr 6th, 2004, 03:26 PM
#1
Thread Starter
New Member
Trimming a String Function with ASP.NET and VB.NET
I'm trying to run a simple function on a dataset field but can not for the life of me figure out how to get it to work.
All I want to do it trim the text that is output by some bound data. The function I have written is below
Code:
<script runat="server">
Function TrimTeaser( strString As String)
strString = strString.Substring (0,4)
End Function
</script>
On the page:
Code:
<%# TrimTeaser(ds_main_news.FieldValue("headerText", Container)) %>
I have tried so many variations and all either complain of missing Expressions, no String data, or it simply does not print to the page. Help!
Cheers,
Jeff
-
Apr 6th, 2004, 03:44 PM
#2
Frenzied Member
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Apr 6th, 2004, 03:55 PM
#3
Thread Starter
New Member
So I changed it to Substring$ and the page renders without errors, but nothing shows up where the trimmed string is supposed to.
Code:
<script runat="server">
Function TrimTeaser( strString As String)
strString = strString.Substring$ (0,4)
End Function
</script>
-
Apr 6th, 2004, 11:03 PM
#4
I wonder how many charact
You are missing one VERY IMPORTANT line of code my friend.
IF you will recall, a function is differentiated from a Sub by one important thing... it RETURNS something.
You have no return in your function, effectively returning nothing.
VB Code:
<script runat="server">
Function TrimTeaser(strString As String)
Return strString.SubString(0,4)
End Function
</script>
That said, if that's all your function does, you might as well not even create a function for it, and skip the overhead.
Code:
<%# DirectCast(ds_main_news.FieldValue("headerText", Container),String).SubString(0,4) %>
If you get an error with the code immediately above, its because I don't use Crystal reports, and therefore am unclear what fieldvalue returns, I only guess its an object of some kind. You may have to substitute convert.toString instead.
Last edited by nemaroller; Apr 6th, 2004 at 11:12 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|