运行时错误6 - OVERFLOW

时间:2013-11-27 10:03:22

标签: vb6

我想解析一个大尺寸的文本文件,文本文件的大小是257MB。我解析大文件后使用listview查看解析数据我想将其保存为excel文件但每次单击按钮保存为excel文件我都会收到此错误“运行时6溢出”

下面是我将解析数据保存为excel文件的代码

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

我需要你的帮助!!提前谢谢你..

1 个答案:

答案 0 :(得分:4)

如果您的项目数(ListView1.ListItems.Count)大于32767(Integer的最大数量),则会出现溢出错误。

将您的声明更改为:

Dim i as Long

Long允许值为-2,147,483,648到2,147,483,647。

有关详细信息,请参阅MSDN VB6 Data Type Summary