How Do I Wrap a Variable in Quotes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TyIzaeL
    New Member
    • Jun 2007
    • 4

    How Do I Wrap a Variable in Quotes

    I'm working with a program to get directories and file types. If I could just get around this problem I'd be done. What I need to do is wrap a [variable] string in quotes before writing it to a text file. I am still pretty new to programming and I've been googling for about the past fourty-five minutes.

    Here is the section of code that is giving me trouble.
    Code:
    Do While Not SR3.Peek = -1
         SW3.WriteLine("compact /c /i " & SR3.ReadLine.Trim)
    Loop
    What it's doing here is reading a file name from a separate text file and writing it to another text file so it can start compact.exe to compress the certain file. The reason I need to figure out how to wrap what's being written in quotes is because spaces in the file path mess things up.

    To aid myself in making sense, here is an example of what is currently being written to the text file:
    Code:
    compact /c /i C:\ATI\Desktop.ini
    Here is what I want:
    Code:
    compact /c /i "C:\ATI\Desktop.ini"
    I've learned some good tricks by reading these forums, but this is my first time posting. I appreciate any help yo uguys could give!
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Just concatenate Chr(34) in there - that's the double-quote character.

    I think there's also a built-in constant named something like vbQuote or vbQuotes which contains the quote character, but don't remember for sure.

    Comment

    • LacrosseB0ss
      New Member
      • Oct 2006
      • 112

      #3
      Just throwing this out there, I don't know for sure, but if spaces are causing a problem, can you not replace those in the path? Use Replace(" ", "%20") is how I would go about it.

      But, as previously mentioned, I haven't tried this. I'm going based on previous knowledge.

      EDIT:
      If Killer gives you a respose though, it's probably better than mine. I trust Killer's judgement. Try that first! ;)
      Last edited by LacrosseB0ss; Jun 11 '07, 05:23 PM. Reason: Add props to Killer

      Comment

      • DJWim
        New Member
        • Jun 2007
        • 8

        #4
        The first reply, incorporated in your code would look like

        Code:
        Do While Not SR3.Peek = -1
             SW3.WriteLine("compact /c /i " & chr$(34) & SR3.ReadLine.Trim & chr$(34))
        Loop

        Comment

        • TyIzaeL
          New Member
          • Jun 2007
          • 4

          #5
          It works flawlessly now!

          Code:
          Do While Not SR3.Peek = -1
               SW3.WriteLine("compact /c /i " & Chr(34) & SR3.ReadLine.Trim & Chr(34))
          Loop
          Many thanks to you Killer42!

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by TyIzaeL
            It works flawlessly now!
            ...
            Many thanks to you Killer42!
            Glad we could help! :)

            But it was a team effort, not just me.

            Comment

            Working...