Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-02 Thread bpascal123
Hi Asa,


I don't think there is any issues with constant, undefined variable types 
or else, i do use option explicit for each module... I use late binding for 
library references. The code that doesn't work is from msdn OpenAsTextStream 
Method http://msdn.microsoft.com/en-us/library/hwfw5c59(v=vs.85).aspx. I 
don't see any mistake I could have made. If yes the code should not be 
working at all.

The first module testy generates an error with this line:

Set f = fs.GetFile(test2.txt) 'Error : File not found ...on removable 
flash FAT32 filesystem...OK on NTFS HD

 
The second module testz works with any storage devices and file system 
without any issue. As you can see, it uses:

Set txtfile = fso.CreateTextFile(Y:\test1.txt, True) 

The True parameter enables writing on the file (btw if you omit true, it 
seems to overwrite a file without warning...

If I understand from your previous post, Fat32 might generate some issues. 
File system library seems to have been there for quite a while as vbscript, 
and other scripts... so I don't see myself to find such a simple bug, given 
that flash memory is widely available and used. To go further with this, I 
should experiment this: format a usb key with NTFS and run the testy script 
from above. I don't know what I will get but from what you say in your 
previous post, it should then work or it's a Vbscript bug...


Following this second discussion on storage technologies, I agree optical 
fiber can transmit data the fastest. However I don't see flash memory last 
for long since it was demonstrated not long that nothing we know about can 
travel faster than light and flash memory is still accessing data using 
semiconductors... After this my knowledge in this area becomes very weak... 
:)

In my mind, what I would see possible to implement to store data is using 
liquid crystal properties and access data using light to reach light speed 
like with optical fibers but a laser is as fast as any other light, like 
printer can come now with LED instead of laser beam... The thing is that 
using LCD would always require some power to keep what is stored in memory 
like with an LCD screen when off is blank or simply like with RAM... and 
else I don't have any idea about the volume of data that can be stored 
using liquid crystals. LCD currently store in very high definition 24 bit 
per pixel...

Pascal Baro

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

--
To post to this group, send email to excel-macros@googlegroups.com


Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-02 Thread bpascal123
Hi Asa,

I don't think there is any issues with constant, undefined variable types 
or else, i do use option explicit for each module... I use late binding for 
library references. The code that doesn't work is from msdn 
OpenAsTextStream Method. I don't see any mistake I could have made. If yes 
the code should not be working at all.

The first module testy generates an error with this line:
Set f = fs.GetFile(test2.txt) 'Error : File not found ...on removable 
flash FAT32 filesystem...OK on NTFS HD
 
The second module testz works with any storage devices and file system 
without any issue. As you can see, it uses:
Set txtfile = fso.CreateTextFile(Y:\test1.txt, True) 
The True parameter enables writing on the file (btw if you omit true, it 
seems to overwrite a file without warning...)

If I understand from your previous post, Fat32 might generate some issues. 
File system library seems to have been there for quite a while as vbscript, 
and other scripts... so I don't see myself finding such a simple bug, given 
that flash memory is widely available and used. To go further with this, I 
should experiment this: format a usb key with NTFS and run the testy script 
from above. I don't know what I will get but from what you say in your 
previous post, it should then work or else it's a Vbscript bug...


Following this second discussion on storage technologies, I agree optical 
fiber can transmit data the fastest. However I don't see flash memory last 
for long since it was demonstrated not long ago that nothing we know about 
can travel faster than light and flash memory is still accessing data using 
semiconductors... After this my knowledge in this area becomes very weak... 
:)

In my mind, what I would see possible to implement to store data is using 
liquid crystal properties and access data using light to reach light speed 
like with optical fibers but a laser is as fast as any other light, like 
printer can come now with LED instead of laser beam... The thing is that 
using LCD would always require some power to keep what is stored in memory 
like with an LCD screen when off is blank or simply like with RAM... and 
else I don't have any idea about the volume of data that can be stored 
using liquid crystals. LCD currently store in very high definition 24 bit 
per pixel...

Pascal Baro

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

--
To post to this group, send email to excel-macros@googlegroups.com


Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-02 Thread bpascal123
The msdn link here OpenAsTextStream 
Methodhttp://msdn.microsoft.com/en-us/library/hwfw5c59(v=vs.85).aspx
I deleted my previous post just to make a few changes as English is not my 
first language and I was even confused reading a last time after posting.

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

--
To post to this group, send email to excel-macros@googlegroups.com


Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-02 Thread bpascal123
Oops my mistake, Set f = fs.GetFile(y:\test2.txt) 

I didn't specify the path, nothing related to flash memory and else...just 
that msdn used filename to declare the path+file variable and I got 
confused,to me filename means filename not file path...since the getfile 
method is linked to thefs  createfile object I didn't think the path needed 
to be included. I realized this before closing the browser window. I didn't 
start by learning POO so there might be more surprised like this for me../

However, I'd like to know about storage technology.

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

--
To post to this group, send email to excel-macros@googlegroups.com


RE: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-02 Thread Asa Rossoff
Hi Pascal,

I'm glad you found the problem (specifying the whole path with Getfile)

 

With late binding you don't need to set a library reference.

If you don't set a library reference, the constants aren't defined. 

You can easily verify the values of the constants in the immediate window
like so:

? ForReading' Should indicate 1 per MSDN

? ForWriting' Should indicate 2

? TriStateUseDefault' Should indicate -2

 

If they are  defined, then you must have set a reference to the library, or
defined them yourself.

If you set a reference to the library, it is preferable to use early
binding, like so:

Dim fs As Scripting.FileSystemObject, f As Scripting.File, ts As
Scripting.TextStream

'.

Set fs = New Scripting.FileSystemObject

'.

If you want to use late binding, it's best to not reference the library at
all, in order to enjoy the main benefits of late binding (different library
versions breaking references on different computers).  Then you need to
either define the constants yourself or just use their numeric values when
you make calls to the library.

Asa

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of bpascal123
Sent: Wednesday, May 02, 2012 1:26 PM
To: excel-macros@googlegroups.com
Subject: Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to
a text file

 

Hi Asa,

 

I don't think there is any issues with constant, undefined variable types or
else, i do use option explicit for each module... I use late binding for
library references. The code that doesn't work is from msdn OpenAsTextStream
Method. I don't see any mistake I could have made. If yes the code should
not be working at all.

 

The first module testy generates an error with this line:

Set f = fs.GetFile(test2.txt) 'Error : File not found ...on removable
flash FAT32 filesystem...OK on NTFS HD

 

The second module testz works with any storage devices and file system
without any issue. As you can see, it uses:

Set txtfile = fso.CreateTextFile(Y:\test1.txt, True) 

The True parameter enables writing on the file (btw if you omit true, it
seems to overwrite a file without warning...)

 

If I understand from your previous post, Fat32 might generate some issues.
File system library seems to have been there for quite a while as vbscript,
and other scripts... so I don't see myself finding such a simple bug, given
that flash memory is widely available and used. To go further with this, I
should experiment this: format a usb key with NTFS and run the testy script
from above. I don't know what I will get but from what you say in your
previous post, it should then work or else it's a Vbscript bug...

 

 

Following this second discussion on storage technologies, I agree optical
fiber can transmit data the fastest. However I don't see flash memory last
for long since it was demonstrated not long ago that nothing we know about
can travel faster than light and flash memory is still accessing data using
semiconductors... After this my knowledge in this area becomes very weak...
:)

 

In my mind, what I would see possible to implement to store data is using
liquid crystal properties and access data using light to reach light speed
like with optical fibers but a laser is as fast as any other light, like
printer can come now with LED instead of laser beam... The thing is that
using LCD would always require some power to keep what is stored in memory
like with an LCD screen when off is blank or simply like with RAM... and
else I don't have any idea about the volume of data that can be stored using
liquid crystals. LCD currently store in very high definition 24 bit per
pixel...

 

Pascal Baro

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 

--
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive

Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-01 Thread dguillett1
DVD http://en.wikipedia.org/wiki/Optical_disc_drive 
A optical drive is essentially what you put CD's DVD's and install discs into


Don Guillett
Microsoft MVP Excel
SalesAid Software
dguille...@gmail.com

From: Asa Rossoff 
Sent: Monday, April 30, 2012 8:44 PM
To: excel-macros@googlegroups.com 
Subject: RE: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a 
text file

Hi Pascal!

Not sure what you mean by optical hard drive  (HDs use electromagnetic 
heads). 

I have not had the chance to try your scripts, and I haven't relally played 
with Scripting.FileSystemObject, but some quick thoughts for you--

 

File locking and permissions are controlled by the OS and the limitations of 
the file system (NTFS/FAT32/ExFAT etc.).  Unless the hardware is read-only or 
sequential-only (i.e. tape) I don't think it has any bearing.

 

USB flash drives are usually formatted with FAT32, hard drives and solid-state 
drives aimed at Windows PCs are usually formatted with NTFS.

 

NTFS supports many more nuances of file locking than FAT.  FAT doesn't support 
file permissions at all.

 

The real issue is most likely file locking issues you are running into on a 
FAT32 volume.  

 

Like I said, I am not versed in use of Scripting.FileSystemObject, but your 
working procedure appears to open the file once (when creating it) and your 
non-working procedure appears to open the file 3 or 4 times.  Perhaps not the 
best way to write the code, but the following single change, just wildly 
guessing, may solve the issue:

fs.CreateTextFile (Y:\test2.txt).Close 'Create a file ** and then close it **

 

 

OH, one other potential issue with your code is the constants 
(TriStateUseDefault, ForReading, ForWriting).  Unless you set a reference to 
the scripting library (I think Microsoft Scripting Runtime), or define the 
constants in your code yourself, these will be undefined.  Further, if you do 
have a reference to the library, for best performance, you should use early 
binding and declare your variables not as Variant (as you did by inference in 
your second procedure) or Object (as you did in your first procedure), but as 
the specific object type and then use the New keyword instead of CreateObject 
to create objects.

 

Asa

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] On 
Behalf Of bpascal123
Sent: Monday, April 30, 2012 11:52 AM
To: excel-macros@googlegroups.com
Subject: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text 
file

 

Hi cyberspace,

 

I have 2 vba scripts with the same purpose, create and write to a text file.

The 1st script works fine when creating and writing the file to my optical hard 
drive and doesn't work on my flash drive.

The 2nd script works fine on both optical and flash drive. 

 

I wonder if the issue is not related to vba coding and Nand flash memory which 

requires a different read-write access to data in comparaison to classic 
optical hard drives.

Can you confirm? 

 

1st script works 1/2:

 

Sub testy() 

 

Dim fs As Object, f As Object, ts As Object

Dim s As String, sTxt As String, lastr As Long

 

Set fs = CreateObject(Scripting.FileSystemObject)

fs.CreateTextFile (Y:\test2.txt) 'Create a file

 

Set f = fs.GetFile(test2.txt)

Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)

ts.Write Hello World

ts.Close

Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)

s = ts.ReadLine

msgbox s

ts.Close

 

End Sub

 

2nd script, works OK :

 

Sub testz()

 

Dim fso, txtfile

Set fso = CreateObject(Scripting.FileSystemObject)

Set txtfile = fso.CreateTextFile(Y:\test1.txt, True)

txtfile.Write (This is a test. ) ' Write a line.

' Write a line with a newline character.

txtfile.WriteLine (Testing 1, 2, 3.)

' Write three newline characters to the file.

txtfile.WriteBlankLines (3)

txtfile.Close

 

End Sub

 

Thanks,

Pascal

 

 

 

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
 
--
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem

Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-01 Thread bpascal123
Hi,

I meant magnetic hard drive...based on the fact both are rotational and 
that myself I was looking for my glasses while writing this post :) , I 
mixed them up... Btw, from latest experiments (i wasn't part of it, i'm not 
a scientist nor do i know about it in detail), nothing travels faster than 
light, then how magnetic drives can be faster than optical drives...and 
applied to flash memory I think sooner or later RD will come back to 
optical storage maybe without rotation...

Asa said it should be related to the file system (FAT32) and not the 
support itself... then I conclude the first code (code 1/2), doesn't 
support FAT32. exFat is the latest filesystem from Microsoft aims at flash 
storage devices.

Pascal

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

--
To post to this group, send email to excel-macros@googlegroups.com


RE: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-01 Thread Asa Rossoff
Hi Pascal,

Actually, my feeling is that your code is leaving a file handle open
unneccesarily and you are having a file sharing/locking violation on FAT32
volumes -- since you only need to have one file handle open at a time, your
code should be correctable (unless VBSCRIPT has some strange bug).

 

Interesting thought about optics.  One issue with any reusable media is that
it has to be physically changed to store information.  Current optical media
receive more destructive changes and require more energy for those changes
than magnetic media.  I imagine the death of removable optical media like
CD/Blu Ray, and being replaced by centralized internet storage and next gen
flash media.  Transmission of data might be more and more wireless, or when
wired, more and more fiber-optic.

 

Asa

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of bpascal123
Sent: Tuesday, May 01, 2012 6:42 AM
To: excel-macros@googlegroups.com
Subject: Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to
a text file

 

Hi,

 

I meant magnetic hard drive...based on the fact both are rotational and that
myself I was looking for my glasses while writing this post :) , I mixed
them up... Btw, from latest experiments (i wasn't part of it, i'm not a
scientist nor do i know about it in detail), nothing travels faster than
light, then how magnetic drives can be faster than optical drives...and
applied to flash memory I think sooner or later RD will come back to
optical storage maybe without rotation...

 

Asa said it should be related to the file system (FAT32) and not the support
itself... then I conclude the first code (code 1/2), doesn't support FAT32.
exFat is the latest filesystem from Microsoft aims at flash storage devices.

 

Pascal

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 

--
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

--
To post to this group, send email to excel-macros@googlegroups.com


RE: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-05-01 Thread Asa Rossoff
P.S.  My comment about the constants may be important and relevant.  The
behavior of your code with undefined constants is quite possibly quite
different than what your code appears to do.  If you don't set a reference
to the Scripting library, your constants will all be undefined.

 

If  you use OPTION EXPLICIT at the top of your module, you will ge a compile
error if you try to use undefined constants/variables.  Always a good idea.

 

You can define the constants yourself, as the Excel help file examples do.

 

Asa

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of Asa Rossoff
Sent: Tuesday, May 01, 2012 7:42 PM
To: excel-macros@googlegroups.com
Subject: RE: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to
a text file

 

Hi Pascal,

Actually, my feeling is that your code is leaving a file handle open
unneccesarily and you are having a file sharing/locking violation on FAT32
volumes -- since you only need to have one file handle open at a time, your
code should be correctable (unless VBSCRIPT has some strange bug).

 

Interesting thought about optics.  One issue with any reusable media is that
it has to be physically changed to store information.  Current optical media
receive more destructive changes and require more energy for those changes
than magnetic media.  I imagine the death of removable optical media like
CD/Blu Ray, and being replaced by centralized internet storage and next gen
flash media.  Transmission of data might be more and more wireless, or when
wired, more and more fiber-optic.

 

Asa

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of bpascal123
Sent: Tuesday, May 01, 2012 6:42 AM
To: excel-macros@googlegroups.com
Subject: Re: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to
a text file

 

Hi,

 

I meant magnetic hard drive...based on the fact both are rotational and that
myself I was looking for my glasses while writing this post :) , I mixed
them up... Btw, from latest experiments (i wasn't part of it, i'm not a
scientist nor do i know about it in detail), nothing travels faster than
light, then how magnetic drives can be faster than optical drives...and
applied to flash memory I think sooner or later RD will come back to
optical storage maybe without rotation...

 

Asa said it should be related to the file system (FAT32) and not the support
itself... then I conclude the first code (code 1/2), doesn't support FAT32.
exFat is the latest filesystem from Microsoft aims at flash storage devices.

 

Pascal

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 

--
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 

--
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any

RE: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a text file

2012-04-30 Thread Asa Rossoff
Hi Pascal!

Not sure what you mean by optical hard drive  (HDs use electromagnetic
heads). 

I have not had the chance to try your scripts, and I haven't relally played
with Scripting.FileSystemObject, but some quick thoughts for you--

 

File locking and permissions are controlled by the OS and the limitations of
the file system (NTFS/FAT32/ExFAT etc.).  Unless the hardware is read-only
or sequential-only (i.e. tape) I don't think it has any bearing.

 

USB flash drives are usually formatted with FAT32, hard drives and
solid-state drives aimed at Windows PCs are usually formatted with NTFS.

 

NTFS supports many more nuances of file locking than FAT.  FAT doesn't
support file permissions at all.

 

The real issue is most likely file locking issues you are running into on a
FAT32 volume.  

 

Like I said, I am not versed in use of Scripting.FileSystemObject, but your
working procedure appears to open the file once (when creating it) and your
non-working procedure appears to open the file 3 or 4 times.  Perhaps not
the best way to write the code, but the following single change, just wildly
guessing, may solve the issue:

fs.CreateTextFile (Y:\test2.txt).Close 'Create a file ** and then close it
**

 

 

OH, one other potential issue with your code is the constants
(TriStateUseDefault, ForReading, ForWriting).  Unless you set a reference to
the scripting library (I think Microsoft Scripting Runtime), or define the
constants in your code yourself, these will be undefined.  Further, if you
do have a reference to the library, for best performance, you should use
early binding and declare your variables not as Variant (as you did by
inference in your second procedure) or Object (as you did in your first
procedure), but as the specific object type and then use the New keyword
instead of CreateObject to create objects.

 

Asa

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of bpascal123
Sent: Monday, April 30, 2012 11:52 AM
To: excel-macros@googlegroups.com
Subject: $$Excel-Macros$$ NAND memory flash-drive, writing from Excel to a
text file

 

Hi cyberspace,

 

I have 2 vba scripts with the same purpose, create and write to a text file.

The 1st script works fine when creating and writing the file to my optical
hard drive and doesn't work on my flash drive.

The 2nd script works fine on both optical and flash drive. 

 

I wonder if the issue is not related to vba coding and Nand flash memory
which 

requires a different read-write access to data in comparaison to classic
optical hard drives.

Can you confirm? 

 

1st script works 1/2:

 

Sub testy() 

 

Dim fs As Object, f As Object, ts As Object

Dim s As String, sTxt As String, lastr As Long

 

Set fs = CreateObject(Scripting.FileSystemObject)

fs.CreateTextFile (Y:\test2.txt) 'Create a file

 

Set f = fs.GetFile(test2.txt)

Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)

ts.Write Hello World

ts.Close

Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)

s = ts.ReadLine

msgbox s

ts.Close

 

End Sub

 

2nd script, works OK :

 

Sub testz()

 

Dim fso, txtfile

Set fso = CreateObject(Scripting.FileSystemObject)

Set txtfile = fso.CreateTextFile(Y:\test1.txt, True)

txtfile.Write (This is a test. ) ' Write a line.

' Write a line with a newline character.

txtfile.WriteLine (Testing 1, 2, 3.)

' Write three newline characters to the file.

txtfile.WriteBlankLines (3)

txtfile.Close

 

End Sub

 

Thanks,

Pascal

 

 

 

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 

--
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post