Help with (probably simple) function problem

Discussion in 'ASP General' started by Jonathan, Apr 6, 2004.

  1. Jonathan

    Jonathan Guest

    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
     
    Jonathan, Apr 6, 2004
    #1
    1. Advertising

  2. Jonathan

    Steven Burn Guest

    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)


    Jonathan <> wrote in message
    news:...
    > 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
     
    Steven Burn, Apr 6, 2004
    #2
    1. Advertising

  3. Jonathan

    Evertjan. Guest

    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


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Apr 6, 2004
    #3
  4. Jonathan

    Bob Barrows Guest

    Jonathan wrote:
    > 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

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Apr 6, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron
    Replies:
    2
    Views:
    781
    Sreejumon[MVP]
    Jul 1, 2003
  2. Ralph Krausse

    Probably a simple answer to 'state'

    Ralph Krausse, Sep 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    366
    Joerg Jooss
    Sep 13, 2004
  3. Replies:
    4
    Views:
    949
    Oliver Wong
    Feb 28, 2006
  4. B. Angell
    Replies:
    4
    Views:
    86
    William James
    Aug 16, 2005
  5. Jim Kronhamn

    Regex problem, probably simple

    Jim Kronhamn, May 14, 2007, in forum: Ruby
    Replies:
    5
    Views:
    103
    Giles Bowkett
    May 17, 2007
Loading...

Share This Page