bebebe
bebebe

Reputation: 339

Run-time error 6 - OVERFLOW

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

Upvotes: 2

Views: 2897

Answers (1)

C-Pound Guru
C-Pound Guru

Reputation: 16368

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.

Upvotes: 3

Related Questions