M
MT DOJ Help Desk
Word 2000
This question may be a little difficult to answer just from the small
snippet of code that I'm posting, but I'll try to explain what is happening.
I have the following code:
While RecordEnd < cbDataLength
AddToLocatesCollection = True
FindMessageMarker
RecordEnd = InStr(RecordStart, cbData, MessageMarker) +
MarkerLength + 1
RecordLength = RecordEnd - RecordStart + 1
cbDataClip = Mid(cbData, RecordStart, RecordLength)
GetRecordNumber
CheckForClearedTag
If AddToLocatesCollection Then CheckRecordExclusionsCollection
If AddToLocatesCollection Then CheckLocatesCollection
If AddToLocatesCollection Then CheckDocument
If AddToLocatesCollection Then LocatesCollection.Add
(cbDataClip)
RecordStart = RecordEnd + 1
Wend
Basically, the contents of cbData come from the clipboard (read in by
another routine), so cbData can contain a HUGE chunk of information. So I
chop up the data and feed it in pieces into cbDataClip. I then pull out a
number of important pieces of information (GetRecordNumber and
CheckForClearedTag), and then run several tests on the data to see if I want
to add it to a collection. The collection that data gets added to is
eventually processed again, and all the items in the collection are pasted
into the document. It all works pretty well.
Tonight, I did my first large scale test of the program, and I encountered
the following error:
Runtime error '6':
Overflow
In debugging the program I found that I had declared RecordStart as and
integer, and the the value of RecordStart was exceeding the limit for an
integer. I was able to fix the bug by declaring RecordStart as Long. This
should work because RecordStart, in practical use, should never exceed the
limit for an integer (my test was purposely the hairiest scenario I could
devise, so was beyond what would be seen in normal use by a factor of
probably about 100), let alone the limit for a Long data type. My test
string of data was almost 45,000 character in length. In practice, the data
being processed at any one time will rarely exceed 1,000 characters, and I
don't know of any instances where it has ever exceeded 5,000 characters.
I thought about redefining cbData each time through, so that it would throw
out the data that has just been processed and, in essence, move everything
remaining in cbData forward. This would prevent RecordStart from ever
exceeding the limit for an integer.
So here's my question. Would it be better to redefine cbData and avoid the
problem of hitting the maximum for an integer, or is my solution good
enough?
-- Tom
MT DOJ Help Desk
Making the world a safer place.
This question may be a little difficult to answer just from the small
snippet of code that I'm posting, but I'll try to explain what is happening.
I have the following code:
While RecordEnd < cbDataLength
AddToLocatesCollection = True
FindMessageMarker
RecordEnd = InStr(RecordStart, cbData, MessageMarker) +
MarkerLength + 1
RecordLength = RecordEnd - RecordStart + 1
cbDataClip = Mid(cbData, RecordStart, RecordLength)
GetRecordNumber
CheckForClearedTag
If AddToLocatesCollection Then CheckRecordExclusionsCollection
If AddToLocatesCollection Then CheckLocatesCollection
If AddToLocatesCollection Then CheckDocument
If AddToLocatesCollection Then LocatesCollection.Add
(cbDataClip)
RecordStart = RecordEnd + 1
Wend
Basically, the contents of cbData come from the clipboard (read in by
another routine), so cbData can contain a HUGE chunk of information. So I
chop up the data and feed it in pieces into cbDataClip. I then pull out a
number of important pieces of information (GetRecordNumber and
CheckForClearedTag), and then run several tests on the data to see if I want
to add it to a collection. The collection that data gets added to is
eventually processed again, and all the items in the collection are pasted
into the document. It all works pretty well.
Tonight, I did my first large scale test of the program, and I encountered
the following error:
Runtime error '6':
Overflow
In debugging the program I found that I had declared RecordStart as and
integer, and the the value of RecordStart was exceeding the limit for an
integer. I was able to fix the bug by declaring RecordStart as Long. This
should work because RecordStart, in practical use, should never exceed the
limit for an integer (my test was purposely the hairiest scenario I could
devise, so was beyond what would be seen in normal use by a factor of
probably about 100), let alone the limit for a Long data type. My test
string of data was almost 45,000 character in length. In practice, the data
being processed at any one time will rarely exceed 1,000 characters, and I
don't know of any instances where it has ever exceeded 5,000 characters.
I thought about redefining cbData each time through, so that it would throw
out the data that has just been processed and, in essence, move everything
remaining in cbData forward. This would prevent RecordStart from ever
exceeding the limit for an integer.
So here's my question. Would it be better to redefine cbData and avoid the
problem of hitting the maximum for an integer, or is my solution good
enough?
-- Tom
MT DOJ Help Desk
Making the world a safer place.