|
-
Aug 15th, 2012, 10:56 AM
#1
Thread Starter
New Member
Fixing "runtime error 6" by replacing "Integer" with "Long"
In the spirit of computers never needing more than 640k, Micro$oft, in their supreme wisdom, made integers in vbs both slow and having a maximum value of only 32,767. Therefore, my ms word vbs code gives a 'runtime error 6' when I have more than 32,767 paragraphs in the word document. Obviously, I need to convert my vbs code to handle a larger number of paragraphs.
What I've learned after hitting google and searching a little in this forum is that I need to do a global replace of "Integer" with "Long". But even after doing that, the script crashes word without any error, as I am using the "on error" command. (Even though it is an atrocious solution, it is the fastest IMO.)
Question, which lines below need to be changed? To reduce the # of lines to be reviewed, I've removed duplicated lines and the lines I am sure are not the problem.
Code:
Dim Reds As Integer
Dim counter As Integer
Dim SBar As Boolean
Dim TrkStatus As Boolean
Dim eTime As Single
Dim oParRef As Paragraph
Dim oParChk As Paragraph
Dim numberofparagraphsindoc As Integer
numberofparagraphsindoc = ActiveDocument.Paragraphs.Count
Reds = 0
Set oParChk = oParRef.Next
counter = counter + 1
Loop Until oParRef Is Nothing
If oParRef.Range = oParChk.Range Then
oParChk.Range.Delete
Reds = Reds + 1
Set oParChk = oParChk.Next
If Len(oParRef.Range.Text) > 1 Then
Loop Until oParChk Is Nothing
Set oParRef = oParRef.Next
Set oParChk = oParRef.Next
Set oParRef = ActiveDocument.Range.Paragraphs(1)
ActiveDocument.TrackRevisions = TrkStatus
eTime = Timer
The red code is now "Long." What else need to be changed? Do I need a command like
Code:
Dim oParRef As LongParagraph
?
Jason
-
Aug 15th, 2012, 04:34 PM
#2
Re: Fixing "runtime error 6" by replacing "Integer" with "Long"
afaik there is no such beast a longparagraph
a paragraph variable is an object type
i assume this is really vba code
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 15th, 2012, 04:37 PM
#3
Thread Starter
New Member
Re: Fixing "runtime error 6" by replacing "Integer" with "Long"
Thanks. I guess the real lesson here is clear: on error statements might be faster but are dangerous to use. So all you need to do is that global replace and my code should work?
-
Aug 15th, 2012, 04:43 PM
#4
Re: Fixing "runtime error 6" by replacing "Integer" with "Long"
I guess the real lesson here is clear: on error statements might be faster but are dangerous to use.
if you use proper error handling, you can log the error for future fixing, but just ignoring errors can produce unpredictable results, including other errors
So all you need to do is that global replace and my code should work?
no idea, but i could not see anything obvious in the small amount of code you posted
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 15th, 2012, 04:50 PM
#5
Re: Fixing "runtime error 6" by replacing "Integer" with "Long"
 Originally Posted by jasontaylor7
on error statements might be faster but are dangerous to use.
They are not faster, and are not any more dangerous than other code... unless you are using On Error Resume Next to 'ignore' errors, and it seems like that is what you did.
For more information, see the article What is wrong with using "On Error Resume Next"? from our Classic VB FAQs (in the FAQ forum)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|