运行时错误 6 - 溢出
我想解析一个很大的文本文件,文本文件的大小是 257MB.解析大文件后,我使用列表视图查看解析数据我想将其另存为 excel 文件,但每次单击另存为 excel 文件"按钮时,都会出现此错误运行时 6 溢出"
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"
下面是我将解析数据保存为excel文件的代码
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..
如果您的项目数 (ListView1.ListItems.Count
) 大于 32767(Integer
),你会得到一个溢出错误.
If your number of items (ListView1.ListItems.Count
) is greater than 32767 (the max number for an Integer
), you'll get an overflow error.
将您的声明更改为:
Dim i as Long
Long
将允许从 -2,147,483,648 到 2,147,483,647 的值.
A Long
will allow values from -2,147,483,648 through 2,147,483,647.
有关详细信息,请参阅 MSDNVB6 数据类型总结.
For more info, refer to the MSDN VB6 Data Type Summary.