View Full Version : Clear previous textfile data
CADfunk MC
2008-08-13, 11:48 AM
Heres the issue:
AutoCAD reads a textfile for me, then makes a drawing with the data.
The .txt is created from an excell file using vba, and killed when a new file is made in its place. The new file never contains previous data. Yet AutoCAD remembers the data from the previous file, and makes that drawing as well.
Thus my question is:
Does someone know an easy way to clear all the data that might be stored in memory by AutoCAD? (or another way to solve the probem).
rkmcswain
2008-08-13, 12:35 PM
When you say "AutoCAD reads a textfile for me, then makes a drawing with the data.", how is it doing this, using a lisp routine? If so, it sounds like a global variable is being used and appended to each time the routine is run.
CADfunk MC
2008-08-15, 06:50 AM
AutoCAD uses a VBA routine to read the textfile.
I think the information is stored in a global variable (like you said). Is there a way to simply "unload" all information stored in global variables at the end of a routine, without having to look specifically?
B_Roche
2008-08-15, 10:30 AM
>>Is there a way to simply "unload" all information stored in global variables at the end of a routine
well, short of "Not using globals to store data to begin with", create a routine named "Unload_All_Information_Stored_In_Global_Variables", paste the names of all your globals in there, put code in to clear them, and call the routine each time.
Oh, and by the way, you would probably want to clear the variables at the *start* of the routine, not at the end
CADfunk MC
2008-11-28, 11:58 AM
This bug is still pestering me. I found that if I deliberatly let the program do something wrong, it clears it's memory of previous data. I did this by letting it hickup here:
Set fs = CreateObject("Scripting.FileSystemObject")
Set f1 = fs.OpenTextFile("H:\Scripts\test.txt", ForReading)
s = f1.ReadLine
Set s = Nothing
I get the message "compile error, object required".
Can I simulate this error so I don't have to track down the variable that is causing the bug?
Or perhaps there is some way of checking the memory of windows, to see what is going on. Somehow it remember every previous textfile it has read.
Sorry if I don't understand you right
Try this way to clear text file
Sub CrearText()
Dim fs, f1, s As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f1 = fs.OpenTextFile("C:\MyVBA\Empty.txt", ForWriting, True)
s = ""
f1.WriteLine s
f1.Close
Set f1 = Nothing
Set fs = Nothing
End Sub
~'J'~
CADfunk MC
2008-12-02, 11:49 AM
Thank you for thinking along with me Fixo.
I applied your thoughts, and have decided the long way round is the only way.
It seems excell is not shutting down properly, so that must be the problem.
Because the code for subs applied in excel is called from AutoCAD, I have to hide excel behind declerations.
That is where it goes wrong. So I have to do the following with a whole pile of subs:
If Not IsError( .Value) Then
If .Value = "" Then .EntireRow.Delete
Change it to something like this. Big, tiresome job.
If Not IsError(xlApp.Application.ActiveSheet.Cells(Lrow, "J").Value) Then
If xlApp.Application.ActiveSheet.Cells(Lrow, "J").Value = "" Then xlApp.Application.ActiveSheet.Cells(Lrow, "J").EntireRow.Delete
B_Roche
2008-12-03, 11:30 AM
Im getting the feeling here that the "long way" is part of the problem.
if I understand you correctly, you are starting an instance of Excel thru Acad VBA, then having Excel output a text file, then reading the text file using FSO, thru Acad VBA?
way too many middlemen, if thats the case.
I'd take the all the code that you have Excel doing to create a text file, make it modular, so that it returns nothing but an array of strings to your calling app in Acad VBA. No file writing. You can check the array contents before you do anything else. And you can clear your array with "Redim" or "Erase".
CADfunk MC
2008-12-05, 10:29 AM
The .txt produced by excel is as it should be now, and Excel shuts down properly (by using LateBinding). I've made very sure no information from excel remains in the memory somewhere by putting this at the end;
xlApp.Application.CutCopyMode = False ' clear clipboard
xlApp.Application.ActiveWorkbook.Saved = True
xlApp.Application.ActiveWorkbook.Close
xlWb.Close
xlApp.Quit
Set xlWb = Nothing
Set xlApp = Nothing
IStartedXL = False
After using Excel, my program continues by using a "filesystemobject".
I was wandering what program was the filesystemobject.
By setting visibility too false I discovered it must be AutoCAD
This filesytemobject is now my main suspect;
Set fs = CreateObject("Scripting.FileSystemObject")
Set f1 = fs.OpenTextFile("H:\Scripts\test.txt", ForReading)
I suspect the "filesystemobject" is remebering the information somehow.
I put this at the end of the macro to make sure it's cleared (to na avail);
' f1.Write ""
' error; bad file mode
f1.Close
f1 = ""
Set fs = Nothing
Anybody got any ideas on this?
CADfunk MC
2008-12-05, 01:18 PM
Finally, I git it pinned down. Noob mistakes on my behalf, but I'm learning as I go.
There were some public global variables outsie of the form, that needed to be private, and in the form.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.