Results 1 to 7 of 7

Thread: Using Quotes in Text

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Posts
    29
    I have to use a quote in a string variable. How do I assign it to a string without it ending the string altogether? If someone has the Ascii numder for it that would help as well.

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    Please try this:

    strMyString = Chr$(34) & "My Text" & Chr(34)

    Hope it helps.

  3. #3
    Guest

    Cool

    Chr$(34) will give you "

    but try "" to get " inside your string

    ie msgbox """fred""" will display "fred"

    clear as mud!

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Originally posted by MadWorm
    Chr$(34) will give you "

    but try "" to get " inside your string

    ie msgbox """fred""" will display "fred"

    clear as mud!
    Code:
    """fred"""
    Will result in an error.
    It's because vb thinks that the string is ended after the 2nd ". And then there's just fred and that means nothing.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  5. #5
    Guest

    Smile

    Try it!

    Code:
    Private Sub Command1_Click()
    MsgBox """fred"""
    End Sub
    works fine on my machine Win2k VB6 ent SP4

  6. #6
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    I'm afraid you're wrong oetje. I do prefer xmin's method though. It just looks strange when you've got thousands of quotes in one string!

    Here you go. Straight from MSDN.

    Printing Quotation Marks in a String
    Sometimes quotation marks (" ") appear in a string of text.

    She said, "You deserve a treat!"

    Because strings assigned to a variable or property are surrounded by quotation marks (" "), you must insert an additional set of quotation marks for each set to display in a string. Visual Basic interprets two quotation marks in a row as an embedded quotation mark.

    For example, to create the preceding string, use the following code:

    Text1.Text = "She said, ""You deserve a treat!"" "

    To achieve the same effect, you can use the ASCII character (34) for a quotation mark:

    Text1.Text = "She said, " & Chr(34) + "You deserve a treat!" & Chr(34)


  7. #7
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Sorry, I was wrong.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

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