Results 1 to 13 of 13

Thread: Line count in 500+ line textbox

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    Unhappy

    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)
    Thanks,
    Chris

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Lincolnshire, UK
    Posts
    111
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    Unhappy 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?
    Thanks,
    Chris

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    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?
    Thanks,
    Chris

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    Talking Never Mind!!

    I set my variable as no type and it worked wonderfully well. Thank you for the advice, HeSaidJoe.
    Thanks,
    Chris

  7. #7
    Lively Member
    Join Date
    Jul 2000
    Location
    Ca
    Posts
    106
    how did u even begin on counting the lines of a textbox?

  8. #8
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Arrow 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.

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    Talking 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.
    Thanks,
    Chris

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    Exclamation 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.
    Thanks,
    Chris

  11. #11
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Thumbs up 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.

  12. #12

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    Unhappy 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?
    Thanks,
    Chris

  13. #13
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Exclamation 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
  •  



Click Here to Expand Forum to Full Width