Results 1 to 7 of 7

Thread: Inserting Text in a Memo Field...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Fort Lauderdale, FL
    Posts
    98

    Inserting Text in a Memo Field...

    OK, so I'm trying to extract code from a few different projects I've done to make a cute little personal library.
    (I'm also working on a project at work documenting rules created in our app, so this will come in handy)
    Basically, what I've got so far is a variable that has an entire VB procedure in it. I want to insert that variable into a memo field in Access. Unfortunately, because it's code, there are loads of quotes and spaces and all sorts of things that make it hard to interpert as just one string.
    Is there anyway to loop through a paragraph (or a procedure in this case) write each line into a variable and then update a memo field with that variable with out doing a search through the whole string and doubling up the quotes?

    Any help is appreciated.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    If you just want to double up the quotes, why not use the Replace() function?, i.e.
    VB Code:
    1. sFormatted = Replace(sRawCode, "'", "''")

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Fort Lauderdale, FL
    Posts
    98
    That won't work unfortunately.
    If I search for each " and replace it with "" then I'll never get past the first ". I end up with """"""""""""""""""""""""""""""""""""""" for eternity.

    Any other ideas?
    The worst part is I really need this done in about 30 minutes.

    Possible, right? :-)

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    If you use the actual Replace() function in VB you don't have to do any kind of manual search and replace, it will convert all instances of the specified character/string into the replacement character/string.

    The Replace() function is only available in VB6, I believe.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Fort Lauderdale, FL
    Posts
    98
    I know, but I'm in VB 5 right now. And wouldn't it still replace every " with a "" making it endless?

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    No, it wouldn't be endless as it would do something like this:
    VB Code:
    1. Public Function ReplaceEx(ByVal sExpression As String, ByVal sFind As String, ByVal sReplace As String) As String
    2.     Dim lChar As Long
    3.     Dim sNew As String
    4.     Do
    5.         lChar = InStr(sExpression, sFind)
    6.         If lChar Then
    7.             sNew = sNew & Left(sExpression, lChar - 1) & sReplace
    8.             sExpression = Mid(sExpression, lChar + Len(sFind))
    9.         End If
    10.     Loop While lChar
    11.     ReplaceEx = sNew & sExpression
    12. End Function

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Fort Lauderdale, FL
    Posts
    98
    Thank you so much! It works beautifully!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width