Help with (probably simple) function problem

J

Jonathan

Hi, I'm having the hardest time finding how to do this on here and in
the books I've looked at so far.
How can I simply return a value for a function?

I want to try something like this (a function to replace certain
elements in a string), but I can't figure out how to return the final
product:

Function replaceit(somestring)
resultstring = Replace(somestring,"_","")
return resultstring '<------- this is one thing I tried
End Function

If I then take a string (say mystring, with a value of
'some_characters'), then I thought I could apply the following to it:

mynewstring = replaceit(mystring)

And end up with a new value of "somecharacters".

The reason I want to be able to do this with a function rather than
directly on each string is to avoid having to type in multiple
replacement codes for each string I want to replace.

Can someone tell me what I'm doing (or not doing) wrong?

Thanks
 
S

Steven Burn

Function ReplaceIt(strText, strCharToReplace, strReplaceWith)
If Len(strText) <> "" Then
ReplaceIt = Replace(strText, strCharToReplace, strReplaceWith)
End If
End Function

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 
E

Evertjan.

Jonathan wrote on 06 apr 2004 in microsoft.public.inetserver.asp.general:
Function replaceit(somestring)
resultstring = Replace(somestring,"_","")
return resultstring '<------- this is one thing I tried
End Function

Function replaceit(somestring)
replaceit= Replace(somestring,"_","")
End Function
 
B

Bob Barrows

Jonathan said:
Hi, I'm having the hardest time finding how to do this on here and in
the books I've looked at so far.
How can I simply return a value for a function?

I want to try something like this (a function to replace certain
elements in a string), but I can't figure out how to return the final
product:

Function replaceit(somestring)
resultstring = Replace(somestring,"_","")
return resultstring '<------- this is one thing I tried
End Function
In jscript/javascritp, you use the return statement. In vb/vba/vbscript, you
set the function equal to the value you wish to return:

Function replaceit(somestring)
resultstring = Replace(somestring,"_","")
replaceit=resultstring
End Function

You can download the vbscript documentation from here:
http://tinyurl.com/7rk6


HTH,
Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top