write string to text file without quotes, or delete the quot
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
write string to text file without quotes, or delete the quot

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
Mandy
Guest





Posted: Thu Jan 06, 2005 12:46 am    Post subject: write string to text file without quotes, or delete the quot Reply with quote

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!

Back to top
Oberer
Guest





Posted: Thu Jan 06, 2005 1:56 am    Post subject: Re: write string to text file without quotes, or delete the Reply with quote

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?
Back to top
Mandy
Guest





Posted: Thu Jan 06, 2005 2:45 am    Post subject: Re: write string to text file without quotes, or delete the Reply with quote

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.

Back to top
James Belshan
Guest





Posted: Thu Jan 06, 2005 3:33 am    Post subject: Re: write string to text file without quotes, or delete the Reply with quote

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


Quote:
''''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)
>
Back to top
Nathan Taylor
Guest





Posted: Thu Jan 06, 2005 3:56 am    Post subject: Re: write string to text file without quotes, or delete the Reply with quote

Try changing Write #1 to Print #1.
Regards - Nathan
Back to top
Mandy
Guest





Posted: Thu Jan 06, 2005 6:52 pm    Post subject: Re: write string to text file without quotes, or delete the Reply with quote

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.
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB