|
-
Sep 8th, 2000, 09:04 AM
#1
Thread Starter
Member
I have a line count function in a text box but when I get up to 500 to 600 lines I get an overflow when I try to lode the text from the beginning to the current position into a variable. I'm doing it by counting chr(13)'s from the beginning to the current cursor position. Can I trap this error so my app doesn't crash. I'm very unfamiliar with error handleing. Any help would be very appreciated. I think the error number is 6 but the following code does nothing:
Code:
if err.number = 6 then
exit function
end if
Checkline = mid(text1.text, 0, text1.selstart)
-
Sep 8th, 2000, 09:36 AM
#2
Lively Member
Error handling is something like the following
The Most Basic!
On Error Resume Next
If an error occours, this just ignores it and carries on - Beware! This may mean that variables have not been set etc and can cause some serious hassle
Prefered Method
On Error Goto {MyHandle}
Where MyHandle is a line marker such as
ErrorHandler:
afterwards you say
select case err.number
case 6
{whatever you want to do}
There are several resume functions to use, these are:
resume next - Carry on at the next statement after the error
Resume - Retry the function
Resume {Label} - Resume execution at the specified label (e.g. ReStartPos
Any questions, Email me ([email protected])
Cheers
Chris
-
Sep 8th, 2000, 09:52 AM
#3
Thread Starter
Member
Yea, but...
The problem is even if my code looks like this:
Code:
If err.number <> 0 Then
Exit Function
End if
MyString = (text1.text, 0, text1.selstart)
I still get the overflow error. Why is that?
-
Sep 8th, 2000, 10:04 AM
#4
_______
<?>
Overflow usually relates to math evaluations.
perhaps a var declared as integer or single when
it should be double or a loop that is never ending
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 8th, 2000, 10:06 AM
#5
Thread Starter
Member
Types of vars...
The problem may be that my var type string cannot hold the whole text1.text. Could that be it? If I don't designate the var as string will it hold more?
-
Sep 8th, 2000, 10:51 AM
#6
Thread Starter
Member
Never Mind!!
I set my variable as no type and it worked wonderfully well. Thank you for the advice, HeSaidJoe.
-
Sep 8th, 2000, 05:41 PM
#7
Lively Member
how did u even begin on counting the lines of a textbox?
-
Sep 8th, 2000, 09:56 PM
#8
Fanatic Member
Courtesy of Megatron....
Hi Sonicblis,
Check out this thread that is a more efficient way to solve your problem: http://forums.vb-world.net/showthrea...threadid=30131
I set my variable as no type
When you do this, VB assigns the variable as a Variant, which eats up a lot of unnecessary memory. With Megatron's solution, this is avoided.
All the best.
-
Sep 11th, 2000, 08:02 AM
#9
Thread Starter
Member
A billion times more efficient.
Thanks for the reference. I was experiencing a half second lag when I got up to about 800 or so lines with my home grown function.
-
Sep 11th, 2000, 08:22 AM
#10
Thread Starter
Member
WOW!
That's amazingly fast. I can count up to 32000 lines or so and if I go higher than that, I need to get a life and do something besides counting lines. Thanks again for the help.
-
Sep 11th, 2000, 09:15 AM
#11
Fanatic Member
Anytime...
However, like I said in my earlier post, the real credit goes to Megatron.
I can count up to 32000 lines or so and if I go higher than that, I need to get a life and do something besides counting lines.
I agree. 
All the best.
-
Sep 11th, 2000, 10:18 AM
#12
Thread Starter
Member
Oops!
This returns the total line count only. What if I want to count only to the cursor? Is there a way to customize for that functionality?
-
Sep 11th, 2000, 10:32 AM
#13
Fanatic Member
A start, maybe.
Maybe you can use a combination of Megatron's code with the Text1.SelStart property to figure out a way to do what you need to do. The SelStart property takes into account the position of the cursor in a multi-line textbox.
I wish I could be of more help, but I don't have the time right now.
All the best.
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
|