我有一个复杂的代码,但总而言之,我有这个:
一个RecordSet
命名的rstRecords
;
全局string
变量命名StrLetters
;
一个string
名为的变量,每次运行时StrText
都有一个内容;
一个。different
loop
While Loop
每次loop
去的next
时候,它Add more content to the string StrLetters
。喜欢:
Do While Not rstRecords.EOF
'Codes Here
Here I call a method named FeedLetter, that has lot of codes but also feed this string
Loop
Private Sub FeedLetter()
'Lot of code
'And Here I feed that string
StrLetters = StrLetters + StrText
End Sub
当它有很多记录时,您将鼠标放在变量上StrLetters
时,它会显示此工具提示<Out Of Memory>
。以及以下错误,String Out of Space
.
当 Theloop
结束时,一个方法将使用 the 的值StrLetters
并打印在纸上。
我知道它被解雇了,因为在VB6
变量中有一个Max Lengh Value
.
我只是想知道解决这个问题的方法...
更新
这是发生错误的地方(cStringBuilderClass
Dave 给出的方法)。
我打电话:
Buffer.CapacityIncrement = Len(strIncommingContent)
Buffer.Append (strIncommingContent)
错误发生在这里:
Public Sub EnsureCapacity(ByVal lngMinimum As Long)
Dim lngDiff As Long
If ((m_lngCapacity < lngMinimum) And (lngMinimum > 0)) Then
' If current capacity isn't enough, then figure out how many capacity increments you need to meet
' the given minimum
lngDiff = lngMinimum - m_lngCapacity
If (lngDiff < m_lngCapacityIncrement) Then
' The If...ElseIf... is quicker than the math in the ElseIf
lngDiff = m_lngCapacityIncrement
ElseIf (lngDiff > m_lngCapacityIncrement) Then
' Note that the division is using \ operator instead of /. \ truncates decimal part
lngDiff = ((lngDiff \ m_lngCapacityIncrement) + 1) * m_lngCapacityIncrement
End If
m_str = m_str & String$(lngDiff, vbNullChar)
m_lngCapacity = (m_lngCapacity + lngDiff)
End If
End Sub