|
Subject:
|
formating text function.
|
|
Posted By:
|
cangerer
|
Post Date:
|
10/15/2003 10:02:33 AM
|
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.
|
|
Reply By:
|
pgtips
|
Reply Date:
|
10/15/2003 10:09:47 AM
|
Your "function" has no return value. You need to put applyEntryFormat = strInput at the end of the function.
|
|
Reply By:
|
Acidecitrix
|
Reply Date:
|
10/16/2003 3:07:20 PM
|
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...
|
|
Reply By:
|
pgtips
|
Reply Date:
|
10/17/2003 3:01:43 AM
|
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.)
|
|
Reply By:
|
Acidecitrix
|
Reply Date:
|
1/2/2004 9:32:46 PM
|
Sorry for my little mistake, I wrote my post for pedagogical purpose only
|
|
Reply By:
|
Acidecitrix
|
Reply Date:
|
1/2/2004 9:37:00 PM
|
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...
|