Reed from and write to TXT FILE

Reed from and write to TXT FILE

Anonymous
Not applicable
492 Views
9 Replies
Message 1 of 10

Reed from and write to TXT FILE

Anonymous
Not applicable
HI,
I am using VBA editor inside AutoCAD to write my program.
in my program there are variables a1,a2,...a10. and when I run the program I need the program to reed the variables value from TXT file , Also I need to save the program result at text file , please tell me how can I reed and write from and to TXT file. looking for your help
thank you alot
0 Likes
493 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
1. Start Acad;
2. Get into VBA Editor;
3. Press "F1" key;
4. Select "Index" tab and enter "Open";
5. Double-click "Open Statement".

You get detailed explanation on how to open a file for reading/writing and
examples.

wrote in message news:4872659@discussion.autodesk.com...
HI,
I am using VBA editor inside AutoCAD to write my program.
in my program there are variables a1,a2,...a10. and when I run the program I
need the program to reed the variables value from TXT file , Also I need to
save the program result at text file , please tell me how can I reed and
write from and to TXT file. looking for your help
thank you alot
0 Likes
Message 3 of 10

Anonymous
Not applicable
Try these samples,

Public Sub WriteFile()
Open "C:\Testfile.txt" For Output As #1 'Open file for output
Write #1, "Hello World", 234 'Write comma-delimited data or
variables a1,a2,...a10
Close #1 'Close file
End Sub

Public Sub ReadFile()
Dim MyString, MyNumber

Open "C:\Testfile.txt" For Input As #1 'Open file for input

Do While Not EOF(1) 'Loop until end of file
Input #1, MyString, MyNumber 'Read data into two variables
a1,a2
Debug.Print MyString, MyNumber 'Print data to the Immediate window
Loop
Close #1 'Close file
End Sub


John Coon




"Norman Yuan" wrote in message
news:4872637@discussion.autodesk.com...
1. Start Acad;
2. Get into VBA Editor;
3. Press "F1" key;
4. Select "Index" tab and enter "Open";
5. Double-click "Open Statement".

You get detailed explanation on how to open a file for reading/writing and
examples.

wrote in message news:4872659@discussion.autodesk.com...
HI,
I am using VBA editor inside AutoCAD to write my program.
in my program there are variables a1,a2,...a10. and when I run the program I
need the program to reed the variables value from TXT file , Also I need to
save the program result at text file , please tell me how can I reed and
write from and to TXT file. looking for your help
thank you alot
0 Likes
Message 4 of 10

Anonymous
Not applicable
Is there a reason you'd suggest this over the FileSystemObject of WSH?

(Using FSO seems MUCH easier and logical, though I'm not as versed as many
in here.)

"Norman Yuan" wrote in message
news:4872637@discussion.autodesk.com...
1. Start Acad;
2. Get into VBA Editor;
3. Press "F1" key;
4. Select "Index" tab and enter "Open";
5. Double-click "Open Statement".

You get detailed explanation on how to open a file for reading/writing and
examples.

wrote in message news:4872659@discussion.autodesk.com...
HI,
I am using VBA editor inside AutoCAD to write my program.
in my program there are variables a1,a2,...a10. and when I run the program I
need the program to reed the variables value from TXT file , Also I need to
save the program result at text file , please tell me how can I reed and
write from and to TXT file. looking for your help
thank you alot
0 Likes
Message 5 of 10

Anonymous
Not applicable
I second the FileSystemObject approach. Go into help and do a search for
"TextStream" and there should be an example for reading/writing to text
files there.

-Chris

"Norman Yuan" wrote in message
news:4872637@discussion.autodesk.com...
1. Start Acad;
2. Get into VBA Editor;
3. Press "F1" key;
4. Select "Index" tab and enter "Open";
5. Double-click "Open Statement".

You get detailed explanation on how to open a file for reading/writing and
examples.

wrote in message news:4872659@discussion.autodesk.com...
HI,
I am using VBA editor inside AutoCAD to write my program.
in my program there are variables a1,a2,...a10. and when I run the program I
need the program to reed the variables value from TXT file , Also I need to
save the program result at text file , please tell me how can I reed and
write from and to TXT file. looking for your help
thank you alot
0 Likes
Message 6 of 10

Anonymous
Not applicable
Scripting.FileSystem object is not recommended to be used in VB/VBA program.
There are lots of talks in various VB related NGs that are against using
FileSystem object in VB/VBA program. It is designed for Windows scripting
specifically, and many system administrators even choose to disable Win.
script. With VB/VBA intrinsic file function, there is nothing you cannot do
wihle with FileSystem object you can. Most experienced VB programmers would
definitely avoid to use Scripting.FileSystem object in their VB/VBA program
whenever they can.

"Chris Shoemaker" wrote in message
news:4873461@discussion.autodesk.com...
I second the FileSystemObject approach. Go into help and do a search for
"TextStream" and there should be an example for reading/writing to text
files there.

-Chris

"Norman Yuan" wrote in message
news:4872637@discussion.autodesk.com...
1. Start Acad;
2. Get into VBA Editor;
3. Press "F1" key;
4. Select "Index" tab and enter "Open";
5. Double-click "Open Statement".

You get detailed explanation on how to open a file for reading/writing and
examples.

wrote in message news:4872659@discussion.autodesk.com...
HI,
I am using VBA editor inside AutoCAD to write my program.
in my program there are variables a1,a2,...a10. and when I run the program I
need the program to reed the variables value from TXT file , Also I need to
save the program result at text file , please tell me how can I reed and
write from and to TXT file. looking for your help
thank you alot
0 Likes
Message 7 of 10

Anonymous
Not applicable
Hmmmm.....

>Most experienced VB programmers would definitely avoid to use
Scripting.FileSystem object in their
>VB/VBA program whenever they can.
0 Likes
Message 8 of 10

Anonymous
Not applicable
So, so true. Remember when the new security model hit those of us trying to do Outlook Web Access and scripting?
0 Likes
Message 9 of 10

Anonymous
Not applicable
Nothing you can't do perhaps, but often at the expense of being 10X more
complex then FSO for anything more advanced. Your point however about ease
of use vs risk for just reading and writing to a text file though is a good
one.

-Chris

"Norman Yuan" wrote in message
news:4873525@discussion.autodesk.com...
Scripting.FileSystem object is not recommended to be used in VB/VBA program.
There are lots of talks in various VB related NGs that are against using
FileSystem object in VB/VBA program. It is designed for Windows scripting
specifically, and many system administrators even choose to disable Win.
script. With VB/VBA intrinsic file function, there is nothing you cannot do
wihle with FileSystem object you can. Most experienced VB programmers would
definitely avoid to use Scripting.FileSystem object in their VB/VBA program
whenever they can.

"Chris Shoemaker" wrote in message
news:4873461@discussion.autodesk.com...
I second the FileSystemObject approach. Go into help and do a search for
"TextStream" and there should be an example for reading/writing to text
files there.

-Chris

"Norman Yuan" wrote in message
news:4872637@discussion.autodesk.com...
1. Start Acad;
2. Get into VBA Editor;
3. Press "F1" key;
4. Select "Index" tab and enter "Open";
5. Double-click "Open Statement".

You get detailed explanation on how to open a file for reading/writing and
examples.

wrote in message news:4872659@discussion.autodesk.com...
HI,
I am using VBA editor inside AutoCAD to write my program.
in my program there are variables a1,a2,...a10. and when I run the program I
need the program to reed the variables value from TXT file , Also I need to
save the program result at text file , please tell me how can I reed and
write from and to TXT file. looking for your help
thank you alot
0 Likes
Message 10 of 10

Anonymous
Not applicable
Thanks for the info, Norman. My thought process was more along the lines of
"if you're using Acad, it's on Windows".

....enlightenment is always a good thing. 😉

"Norman Yuan" wrote in message
news:4873525@discussion.autodesk.com...
Scripting.FileSystem object is not recommended to be used in VB/VBA program.
There are lots of talks in various VB related NGs that are against using
FileSystem object in VB/VBA program. It is designed for Windows scripting
specifically, and many system administrators even choose to disable Win.
script. With VB/VBA intrinsic file function, there is nothing you cannot do
wihle with FileSystem object you can. Most experienced VB programmers would
definitely avoid to use Scripting.FileSystem object in their VB/VBA program
whenever they can.
0 Likes