write string to text file without quotes, or delete the quotes later

Discussion in 'AutoCAD' started by Mandy, Jan 5, 2005.

  1. Mandy

    Mandy Guest

    I'm extracting data using AutoCAD VBA and writing to a text file. However, whenever the data being written is contained in a string variable, it gets written with quotes around it. I don't want the quotes included in the text file.

    First question: Is there a way to write a string to a text file without the quotes around it?

    Second question: Is there a way to open a text file and do a Find and Replace? I'm thinking that if I just wait until I have the text file completely written, I could then open the text file and do a Find and Replace to replace all quotes with nothing. (This is what I have been doing manually in Notepad). I would like to know how to do a Find and Replace, even if there is an answer to the first question... just for future reference.

    Thanks much!
     
    Mandy, Jan 5, 2005
    #1
  2. Mandy

    Oberer Guest

    Mandy, someone with some code will hopefully stop by. I'm pretty sure it's the way you're writing to the file (the method you're using)

    Would you mind posting some of your code?
     
    Oberer, Jan 5, 2005
    #2
  3. Mandy

    Mandy Guest

    OK, this is not complete working code, but this gives the basic idea of what I am trying to do: (I'm getting the circuit number from an object data table, and the start and end points of the line it is associated with, and writing this info to Circuit.txt)

    Dim CircuitNum As String
    Dim X0 As Variant, Y0 As Variant
    Dim X1 As Variant, Y1 As Variant

    strFileName = "C:\\circuit.txt"
    Open strFileName For Append As #1

    (bunch of table crap... snip... )

    If (ODRecords.Record.TableName = "CIRCUIT") Then
    CircuitNum = ODRecords.Record.Item(i).Value
    ''''Write #1, CircuitNum // if I do this Write, the circuit number will have quotes around it
    End If

    (...snip....)

    Loop 'on the tables for the item

    'Before going on to next entity, get this entity's coords.
    ObjectType = oAcadObj.ObjectName

    If (TableName = "CIRCUIT") Then
    Select Case ObjectType

    Case "AcDbLine"
    Set oLineObj = oAcadObj
    X0 = oLineObj.StartPoint(0)
    Y0 = oLineObj.StartPoint(1)
    X1 = oLineObj.EndPoint(0)
    Y1 = oLineObj.EndPoint(1)

    ''''Write #1, CircuitNum, X0, Y0, X1, Y1 // if I write this way, the Circuit Number has quotes around it, but none of the coords do

    strData = CircuitNum & "," & X0 & "," & Y0 & "," & X1 & "," & Y1
    Write #1, strData // by concatenating all of this into one string, now when I write there is one set of quotes around the entire string (before CircuitNum and after Y1)

    End Select

    End If 'table is circuit

    Next 'go to next entity

    Close #1

    The Circuit number is something like 5P266, and what it writes to the text file is "5P266". When I then write out the coordinates, these do not get the quotes around them.
     
    Mandy, Jan 5, 2005
    #3
  4. Mandy,
    The Write# command puts quotes around string variables but not numeric
    variables. It's designed to work with the Read# command, which (I believe)
    will strip the quotes off of a string variable if you Read# it in. Use:

    Print #1, strData or
    Print #1, CircuitNum & "," & X0 & "," & Y0 & "," & X1 & "," & Y1

    to print out your concatenated line. If you ever want to print to the file
    without starting a new line afterward, put a semicolon (;) after your Print#
    statement.

    James

    Circuit Number has quotes around it, but none of the coords do
    of this into one string, now when I write there is one set of quotes around
    the entire string (before CircuitNum and after Y1)
     
    James Belshan, Jan 5, 2005
    #4
  5. Try changing Write #1 to Print #1.
    Regards - Nathan
     
    Nathan Taylor, Jan 5, 2005
    #5
  6. Mandy

    Mandy Guest

    Thank you James and Nathan. I'm a newbie and just stumbling along using bits and pieces of other people's code! So these tips are most helpful.
     
    Mandy, Jan 6, 2005
    #6
Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.