2

i want to parse a large size of text file, the size of the text file is 257MB. i use listview to view the parse data after i parse the large file i want to save it as an excel file but everytime i click the button save as excel file i will got this error "Run-time 6 Overflow"

below is my code to save the parse data as excel file

Private Sub cmd_save_excel_Click()
Dim ExcelObj As Object
Dim ExcelBook As Object
Dim ExcelSheet As Object
Dim i As Integer





Set ExcelObj = New Excel.Application
Set ExcelBook = ExcelObj.Workbooks.Add
Set ExcelSheet = ExcelBook.Worksheets(1)

With ExcelSheet
For i = 1 To ListView1.ListItems.Count
'.Cells(i, 1) = ListView1.ListItems(i).Text
.Cells(i, 1) = ListView1.ListItems(i).SubItems(1)
.Cells(i, 2) = ListView1.ListItems(i).SubItems(2)
.Cells(i, 3) = ListView1.ListItems(i).SubItems(3)
.Cells(i, 4) = ListView1.ListItems(i).SubItems(4)
.Cells(i, 5) = ListView1.ListItems(i).SubItems(5)
.Cells(i, 6) = ListView1.ListItems(i).SubItems(6)
Next
End With

ExcelObj.Visible = True

Set ExcelSheet = Nothing
Set ExcelBook = Nothing
Set ExcelObj = Nothing

End Sub

i need your help!! thank you in advance..

2
  • 3
    alright, thank you GSerg :) Commented Nov 28, 2013 at 15:56
  • @JustinDavies You changed the OP's code and edited in the suggested answer as if it originally was in code. Please never do that. Commented Nov 28, 2013 at 17:26

1 Answer 1

3

If your number of items (ListView1.ListItems.Count) is greater than 32767 (the max number for an Integer), you'll get an overflow error.

Change your declaration to:

Dim i as Long

A Long will allow values from -2,147,483,648 through 2,147,483,647.

For more info, refer to the MSDN VB6 Data Type Summary.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.