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, 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