7 Replies - 741 Views - Last Post: 25 February 2012 - 12:41 AM Rate Topic: -----

#1 manaskr79  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-September 11

SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

Posted 24 February 2012 - 01:29 AM

The following code creates a text file from a list called List1. It's working fine when the list is small but
in case of a large list it is creating a text file but with no contents (size 0 Bytes). Any remedy or suggestions plz.
Private Sub cmdSave_Click()
On Error GoTo errors123
If List1.ListCount = 0 Then
MsgBox "Empty list cannot be exported."
Exit Sub
End If
Dim i As Integer
Dim objFSO As New Scripting.FileSystemObject
Dim objTextFile As TextStream
comdlg.CancelError = True
comdlg.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist
comdlg.Filter = "Text File(*.txt)|*.txt|All Files(*.*)|*.*"
comdlg.InitDir = Text1.Text
comdlg.ShowSave

strEmpFileName = comdlg.FileName
Set objTextFile = objFSO.CreateTextFile(strEmpFileName, ForAppending)
For i = 0 To List1.ListCount - 1
objTextFile.WriteLine List1.List(i)
Next
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing
MsgBox "File successfully saved to " & vbCrLf & comdlg.FileName, vbInformation

errors123:
If Err.Number = 32755 Then
comdlg.FileName = ""
Exit Sub
End If
End Sub

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 274
  • View blog
  • Posts: 1,653
  • Joined: 26-March 09

Re: SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

Posted 24 February 2012 - 01:35 AM

What do you call a large list? How many elements?

As a starting point, look at the datatype you're using to loop through the list. If the list is "large" you may have issues, although I would've expected your error handling to have picked that up (you didn't state whether you get any errors or whether it drops into the error handler).

This post has been edited by maj3091: 24 February 2012 - 02:21 AM

Was This Post Helpful? 0
  • +
  • -

#3 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 18
  • View blog
  • Posts: 258
  • Joined: 21-May 09

Re: SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

Posted 24 February 2012 - 05:32 AM

another thing to notice is that this code is .NET and not vb6
in vb6 you use Print #filenum, variable in order to print a single line
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 274
  • View blog
  • Posts: 1,653
  • Joined: 26-March 09

Re: SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

Posted 24 February 2012 - 08:05 AM

View PostNeku, on 24 February 2012 - 12:32 PM, said:

another thing to notice is that this code is .NET and not vb6
in vb6 you use Print #filenum, variable in order to print a single line


You don't do that using the FileSystemObject. The WriteLine method will write a line appended with a NewLine character.
Was This Post Helpful? 0
  • +
  • -

#5 manaskr79  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-September 11

Re: SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

Posted 24 February 2012 - 11:58 AM

i tried to save from a list of 49253 lines. Actually i listed all the file names of C: drive and save the result to a txt file. if u look at the attached file (i attached the entire prject) & run it to list all the file names of C: drive. u can see actually what's happening. i removed all the error handlings. Then also it is not showing any error but just saving nothing to the created file.
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 274
  • View blog
  • Posts: 1,653
  • Joined: 26-March 09

Re: SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

Posted 24 February 2012 - 12:18 PM

I appreciated you uploaded the project, but I'm not in the habit of downloading files from here.

Try changing your loop variable to be a long instead of an integer.
Was This Post Helpful? 0
  • +
  • -

#7 manaskr79  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-September 11

Re: SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

Posted 24 February 2012 - 10:00 PM

changed it to long but result is still same, also not showing any error. just not doing what the code was supposed to do. is there any limitation of filesystem object?
Was This Post Helpful? 0
  • +
  • -

#8 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 274
  • View blog
  • Posts: 1,653
  • Joined: 26-March 09

Re: SAVING A TEXT FILE (.TXT) WITH LARGE CONTENT

Posted 25 February 2012 - 12:41 AM

As far as I'm aware, there is no limitation on the FSO.

Out of curiosity, I downloaded your code and tried it on my sandbox machine.

First thing, my machine, only had 14,000 files on it, so I added another loop around the write function to write it out 6 times to the file. It did this no problem.

Then I looked at the listbox and realised that it has a maximum limit of around 32 thousand lines (I suspect 32768).

If you put a breakpoint on the line where the loop starts, you will probably find that your list count is a negative number.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1