Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2003, 10:02 AM
Registered User
 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default formating text function.

Greetings,

I have created an ASP function to help with formatting and removing certain certain characters before the data is inserted into a database.

Here is the function
\/\/\/\/\/\/\ code snippet \/\/\/\/\/\/\/\/\/
Function applyEntryFormat(strInput)
    strInput = Replace(strInput, "'", "''")
    strInput = Replace(strInput, "<", "")
    strInput = Replace(strInput, ">", "")
    strInput = Replace(strInput, "&", "")
    strInput = Replace(strInput, vbCrLf, "<br />")
End Function
/\/\/\/\/\/\/\ end code snippet /\/\/\/\/\/\/
Now when I try to apply this function like this

strJournalTitle = applyEntryFormat(Request.Form("journalTitle"))

the variable turns either doesn't get set from the function or gets set to an empty string. Any ideas as to what I can do to fix this problem ?

Any advice is appreciated.

Thanks.
 
Old October 15th, 2003, 10:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Your "function" has no return value. You need to put
Code:
applyEntryFormat = strInput
at the end of the function.
 
Old October 16th, 2003, 03:07 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have two choices :

1- (Recommended!!!)
Use the syntax for the functions :

Function MyFunction (MyFirstArg, MySecondArg)

  'Your code here!

  MyFunction = YourReturnValue

End Function


2- (not so bad, and useful to return many values)
Use the byref arguments with the syntax for the subs :

Sub MySub (ByRef MyFirstArg, ByRef MySecondArg, ByVal AThirdArg)

  'Your code here!

  MyFirstArg = FinalValueForMyFirstArg
  MySecondArg = FinalValueForMySecondArg

End Sub


After the call of MySub, the value of the first variable passed to MySub will be changed to the value of FinalValueForMyFirstArg and the second variable passed to MySub will be changed to the value of FinalValueForMySecondArg. But note that AThirdArg can be change within the sub and all change will be accessible within the sub but the value will not be changed outside of the sub.

So, if you call MySub like this :

MySub variable1, variable2, variable3

the value of variable1 will be the value of FinalValueForMyFirstArg,
the value of variable2 will be the value of FinalValueForMySecondArg and the value of variable3 will be the value of variable3 before the call of MySub.

I use this kind of tricks when I need more then one answer in a call, and I'm not alone most of the Win32 API use that kind of calls.

I hope that this will help one day or another...
 
Old October 17th, 2003, 03:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, but option 2 is of no use in this scenario. If you look at the original post you'll see that the arg passed to the function is
Request.Form("journalTitle") and you can't modify that. (OK the OP could write it to a temporary variable which could then be modified.)
 
Old January 2nd, 2004, 10:32 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for my little mistake, I wrote my post for pedagogical purpose only
 
Old January 2nd, 2004, 10:37 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also notice that I was recommending the solution #1 in that case, solution #2 should ONLY be use when more than one variable need to be return by the call...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Text Formating in ASP.Net Textbox aliirfan84 ASP.NET 2.0 Professional 4 May 25th, 2007 03:04 AM
Formating xpath function result number ronisc XSLT 4 December 20th, 2006 09:04 AM
Formating text bjackman Access VBA 1 August 22nd, 2005 03:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.