Results 1 to 6 of 6

Thread: String With Quotes Blues

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Posts
    93
    I am Trying to write to a text file but It keeps adding quotes to my statement. It is a command and won't run with qoutes around it.

    It looks like this "nbtstat -a >""c:\output.txt"""
    It is supposed to look like this nbtstat -a >"c:\output.txt"

    Here is my code.
    Private Sub Command1_Click()

    'Form Contains Text2, Text1, RichTextBox1, and Command1

    Dim MyCommand As String
    Dim ComputerName As String
    Dim Test As String

    'The Computer You Want Info About.
    ComputerName = Text1.Text

    'Strings the NBTSTAT command with the Computer Name and an Output File.
    MyCommand = "nbtstat -a " & computer & " >" & Chr(34) & "c:\output.txt" & Chr(34)

    'Moves the Command to the Test Varible
    'Then to The Text2 text box to Check Formatting
    Test = MyCommand
    Text2.Text = Test

    'Writes the Command to a Batch File
    Open "C:\Command.bat" For Output As #1
    Write #1, Text2.Text
    Close #1

    'Runs the Batch File
    Shell "C:\Command.bat", vbHide

    'Recieves an Error Because The Batch File Contains Too Many Quotes
    'And the Output File hasn't Been Created
    RichTextBox1.FileName = "C:\Output.txt"
    End Sub

    Thanks for any help
    Brandon

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    try this

    instead of:

    MyCommand = "nbtstat -a " & computer & " >" & Chr(34) & "c:\output.txt" & Chr(34)

    do:

    MyCommand = "nbtstat -a " & computer & " >" & """c:\output.txt"""

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Posts
    93
    I got the exact same Result.

    Thanks
    Brandon

  4. #4
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    You have to use Print # statement for writing data to files without quotes. If you use Write # statement, you'll allways get quotes.
    Example:
    Code:
    Dim fNum As Integer
    fNum=FreeFile
    Open file.dat For Output As fNum
    Print #fNum, "string for output without quotes"
    Close #fNum
    I think this would work fine.
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  5. #5
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Where you have:
    Code:
    Write #1, Text2.Text
    replace it with:
    Code:
    Print #1, Text2.Text
    The "Write" statement puts the quotes around your string. The "Print" statement puts exactly what you tell it to.

    ---------
    oopps, somebody beat me to it.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  6. #6
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    I forgot: FILE.DAT must be quoted ("file.dat")!
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

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