Results 1 to 7 of 7

Thread: Editor line counter !

  1. #1

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Angry Editor line counter !

    I am making an HTML editor, and i'm in the progress of making a counter in the left side of that screen, that shows wich line youre on, like i other editors as editplus... I use sendmessage, but i cant get it too work probably, here's the code i'm using:
    VB Code:
    1. Private Sub Form_Load()
    2. Counter = 1
    3. List1.AddItem Counter
    4. End Sub
    5. ' Note "Counter" IS declared in the declarations !
    6. Private Sub RTB1_Change()
    7. Dim LineCount As Long
    8. LineCount = SendMessage(RTB1.hwnd, EM_GETLINECOUNT, ByVal 0&, ByVal 0&)
    9. ' Add line
    10. If LineCount > PrevCount Then
    11. Counter = Counter + 1
    12. List1.AddItem Counter
    13. End If
    14. ' Delete Line
    15. If LineCount < PrevCount Then
    16. Counter = Counter - 1
    17. List1.RemoveItem Counter
    18. End If
    19. End Sub

    My problem is that if the user deletes more than one line, the listbox only get's one number removed .
    This is driving me nuts !

    Please help !!!

    Thanks in advance !
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  2. #2

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Going too sleep !

    I'm going too sleep now... But that doesn't prevent you guys from answering
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Um, just a question, where do you set PrevCount? Shouldn't your code be something like (assuming it's error free - I can't check the code you do have):
    VB Code:
    1. Private Sub RTB1_Change()
    2. Dim LineCount As Long
    3. PrevCount = LineCount    ' Shouldn't you add this?
    4. LineCount = SendMessage(RTB1.hwnd, EM_GETLINECOUNT, ByVal 0&, ByVal 0&)
    5. ' Add line
    6. If LineCount > PrevCount Then
    7. ...
    Destined.

  4. #4

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Of course...

    Yes ofcourse i should, and it is there
    Just forgot too write it in the post.
    Thanks
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  5. #5
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Oh, perhaps I might actually know.

    In your remove statment, you have
    VB Code:
    1. If LineCount < PrevCount Then
    2. Counter = Counter - 1
    3. List1.RemoveItem Counter
    4. End If
    If I understand correctly, this will only remove one item, even though it may actually be more than one. I don't know where the index starts or stops, but here's a general idea that may work:
    VB Code:
    1. If LineCount < PrevCount Then
    2. Dim diff As Long, i As Integer
    3. diff = PrevCount - LineCount
    4. For i = 1 to diff
    5.    Counter = Counter - 1
    6.    List1.RemoveItem Counter
    7. Next i
    8. End If
    I'm not completely sure, but this might be what you need. Hope it helps in some way.

    Destined.

  6. #6

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Wohoo

    Thanks, i woke up today turn on my computer and saw your piece of code... Suddenly everything made sense...
    Noe it works !!! THANK YOU VERY MUCH !
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  7. #7
    Addicted Member
    Join Date
    Jul 2002
    Location
    BC, Canada
    Posts
    152
    Cool! Glad I could help.

    Now it's my turn to go to bed. Just fixed a computer that had a complete hard drive failure.. *sigh*

    Destined

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