Jump to content
Sign in to follow this  
atomman

Line Numbering For Edit Control

Recommended Posts

i probably re-invented the wheel here, but i couldn't find anything i liked. besides, it was fun!

2 edit controls, side by side. 1st holds numbers (read only, disabled), second is regular edit control with scroll bars. GUI is resizable.

problems:

1) adding lines works fine, but when backspacing in the main edit ctrl, script has to re-draw all the numbers. sure, can drop the 20ms sleep, but this doesn't solve the core problem.

2) using the UP arrow in the main edit ctrl adjusts the line numbers and this is not what i want.

3) and the biggie... haven't figured out how to sync the v-scrolling between the 2 controls.

#include <GUIConstants.au3>
;#Include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL,$ES_READONLY), 0); drop 'readonly' and number 1 deletes on first return
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)

GUICtrlSetState($Edit_Num, $GUI_DISABLE); prevents goofinies when clicking on $Edit_Num control

While 1
    
    $Msg = GUIGetMsg()
    
    Switch $Msg
        
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
    
    If ControlCommand($Form1, "", $Edit_Num, "GetLineCount") < ControlCommand($Form1, "", $Edit_Main, "GetLineCount") Then
            Sleep(20)
            $Line = (@CRLF & (ControlCommand($Form1, "", $Edit_Num, "GetLineCount") + 1))
            GUICtrlSetData($Edit_Num, $Line, "a")
    ElseIf ControlCommand($Form1, "", $Edit_Main, "GetLineCount") < ControlCommand($Form1, "", $Edit_Num, "GetLineCount") Then
            Sleep(20)
            $Line = Send("")
            GUICtrlSetData($Edit_Num, $Line)
    EndIf
    
WEnd

#cs
_GUICtrlEdit_Scroll

_GUICtrlEdit_LineScroll 

Scrolls the text

#Include <GuiEdit.au3>
_GUICtrlEdit_LineScroll($hWnd, $iHoriz, $iVert)
#ce
Edited by atomman

Share this post


Link to post
Share on other sites

i probably re-invented the wheel here, but i couldn't find anything i liked. besides, it was fun!

2 edit controls, side by side. 1st holds numbers (read only, disabled), second is regular edit control with scroll bars. GUI is resizable.

problems:

1) adding lines works fine, but when backspacing in the main edit ctrl, script has to re-draw all the numbers. sure, can drop the 20ms sleep, but this doesn't solve the core problem.

2) using the UP arrow in the main edit ctrl adjusts the line numbers and this is not what i want.

3) and the biggie... haven't figured out how to sync the v-scrolling between the 2 controls.

#include <GUIConstants.au3>
;#Include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL,$ES_READONLY), 0); drop 'readonly' and number 1 deletes on first return
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)

GUICtrlSetState($Edit_Num, $GUI_DISABLE); prevents goofinies when clicking on $Edit_Num control

While 1
    
    $Msg = GUIGetMsg()
    
    Switch $Msg
        
        Case $GUI_EVENT_CLOSE
            Exit
            
    EndSwitch
    
    If ControlCommand($Form1, "", $Edit_Num, "GetLineCount") < ControlCommand($Form1, "", $Edit_Main, "GetLineCount") Then
            Sleep(20)
            $Line = (@CRLF & (ControlCommand($Form1, "", $Edit_Num, "GetLineCount") + 1))
            GUICtrlSetData($Edit_Num, $Line, "a")
    ElseIf ControlCommand($Form1, "", $Edit_Main, "GetLineCount") < ControlCommand($Form1, "", $Edit_Num, "GetLineCount") Then
            Sleep(20)
            $Line = Send("")
            GUICtrlSetData($Edit_Num, $Line)
    EndIf
    
WEnd

#cs
_GUICtrlEdit_Scroll

_GUICtrlEdit_LineScroll 

Scrolls the text

#Include <GuiEdit.au3>
_GUICtrlEdit_LineScroll($hWnd, $iHoriz, $iVert)
#ce
Maybe this

#include <GUIConstants.au3>
#Include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)

GUICtrlSetState($Edit_Num, $GUI_DISABLE); prevents goofinies when clicking on $Edit_Num control

While 1

    $Msg = GUIGetMsg()

    Switch $Msg

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    While _GUICtrlEdit_GetLineCount ($Edit_Main) > _GUICtrlEdit_GetLineCount ($Edit_Num)
        _GUICtrlEdit_AppendText ($Edit_Num, @CRLF & _GUICtrlEdit_GetLineCount ($Edit_Num) + 1)
    WEnd
    
    If _GUICtrlEdit_GetLineCount ($Edit_Main) < _GUICtrlEdit_GetLineCount ($Edit_Num) Then
        $text = GUICtrlRead($Edit_Num)
        For $n = _GUICtrlEdit_GetLineCount ($Edit_Main) To _GUICtrlEdit_GetLineCount ($Edit_Num)
            $text = StringReplace($text, @CRLF & $n, '')
        Next
        GUICtrlSetData($Edit_Num, $text)
    EndIf
    
    While _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main) > _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
        _GUICtrlEdit_Scroll ($Edit_Num, $SB_LINEDOWN)
    WEnd
    
    While _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main) < _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
        _GUICtrlEdit_Scroll ($Edit_Num, $SB_LINEUP)
    WEnd
    
    #cs
        If ControlCommand($Form1, "", $Edit_Num, "GetLineCount") < ControlCommand($Form1, "", $Edit_Main, "GetLineCount") Then
        Sleep(20)
        $Line = (@CRLF & (ControlCommand($Form1, "", $Edit_Num, "GetLineCount") + 1))
        GUICtrlSetData($Edit_Num, $Line, "a")
        ElseIf ControlCommand($Form1, "", $Edit_Main, "GetLineCount") < ControlCommand($Form1, "", $Edit_Num, "GetLineCount") Then
        Sleep(20)
        $Line = Send("")
        GUICtrlSetData($Edit_Num, $Line)
        EndIf
    #ce

WEnd

#cs
    _GUICtrlEdit_Scroll
    
    _GUICtrlEdit_LineScroll
    
    Scrolls the text
    
    #Include <GuiEdit.au3>
    _GUICtrlEdit_LineScroll($hWnd, $iHoriz, $iVert)
#ce

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

works very well!

thanks Martin.

i'm using SciTE 1.74. if you have the same, place the caret after 'EndSwitch', hit return and see what happens.

i get a tab between 'EndSwitc' and 'h', and then the new line.

UPDATE: if i change the language to text, works fine. back to AU3, same problem.

Edited by atomman

Share this post


Link to post
Share on other sites

Wondering if anyone can improve on this. I provided the code, then Martin modified it, and now i'm tinkering with it again.

the goal is 2 edit controls with synchronized scrolling and line numbering.

Issues:

i don't really like using AdLib here, but i don't know how else to do it while keeping CPU usage low. If you do this stuff using If/EndIf, While/WEnd, etc, inside the loop, then CPU will always be high (~8%) as long as the GUI is focused and you move the mouse around (on or off the GUI). i don't know what causes that.

if you change the AdLibEnable() time, different things will happen. sometimes CPU will go to 50% only when holding down BACKSPACE for 40+ lines, other times when holding ENTER for 40+ lines (may have to do with scrolling). it's just not a very pretty solution to what i'm trying to do IMO, but it *almost* works.

#include <GUIConstants.au3>
#Include <GuiEdit.au3>
#Include <Misc.au3>

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)


AdlibEnable("_LineNum", 111)
;AdlibEnable("_ScrollSync", 12)

While 1

    $Msg = GUIGetMsg()

    Switch $Msg

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    
WEnd

Func _LineNum() ; line numbering
    While _GUICtrlEdit_GetLineCount ($Edit_Main) > _GUICtrlEdit_GetLineCount ($Edit_Num)
        _GUICtrlEdit_AppendText ($Edit_Num, @CRLF & _GUICtrlEdit_GetLineCount ($Edit_Num) + 1)
        ;Sleep(1)
    WEnd
    
    If _GUICtrlEdit_GetLineCount ($Edit_Main) < _GUICtrlEdit_GetLineCount ($Edit_Num) Then
        $text = GUICtrlRead($Edit_Num)
        For $n = _GUICtrlEdit_GetLineCount ($Edit_Main) To _GUICtrlEdit_GetLineCount ($Edit_Num)
            $text = StringReplace($text, @CRLF & $n, '')
            ;Sleep(1)
        Next
        GUICtrlSetData($Edit_Num, $text)
    EndIf
;EndFunc
    
;Func _ScrollSync() ; syncronized scrolling
    While _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main) > _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
        _GUICtrlEdit_Scroll ($Edit_Num, $SB_LINEDOWN)
        ;Sleep(1)
    WEnd
    
    While _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main) < _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
        _GUICtrlEdit_Scroll ($Edit_Num, $SB_LINEUP)
        ;Sleep(1)
    WEnd
EndFunc

Share this post


Link to post
Share on other sites

Wondering if anyone can improve on this. I provided the code, then Martin modified it, and now i'm tinkering with it again.

the goal is 2 edit controls with synchronized scrolling and line numbering.

Issues:

i don't really like using AdLib here, but i don't know how else to do it while keeping CPU usage low. If you do this stuff using If/EndIf, While/WEnd, etc, inside the loop, then CPU will always be high (~8%) as long as the GUI is focused and you move the mouse around (on or off the GUI). i don't know what causes that.

if you change the AdLibEnable() time, different things will happen. sometimes CPU will go to 50% only when holding down BACKSPACE for 40+ lines, other times when holding ENTER for 40+ lines (may have to do with scrolling). it's just not a very pretty solution to what i'm trying to do IMO, but it *almost* works.

I've rewritten your _lineNum() function to be more CPU friendly. On my PC it barely registers on the performance tab in Task Manager. There may be scope for a little more performance if you want to have a go. If you don't want to use adlib() then I think you will have to register your own message handler as AUtoIt only processes lost focus messages for edit controls.

Func _LineNum() ; line numbering
    Local $iCount = _GUICtrlEdit_GetLineCount ($Edit_Main)

    If $iCount <> $g_iMainLineCount Then 
        $g_iMainLineCount = $iCount 
        Local $iNumCount = _GUICtrlEdit_GetLineCount ($Edit_Num)
        If $g_iMainLineCount > $iNumCount Then
            For $i = $iNumCount + 1 To $g_iMainLineCount
                _GUICtrlEdit_AppendText ($Edit_Num, @CRLF & $i)
            Next
        ElseIf $g_iMainLineCount < $iNumCount Then
            $text = GUICtrlRead($Edit_Num)
            StringRegExpReplace($text,"(\r\n[0-9]*){" & $g_iMainLineCount - $iNumCount & "}^", "")
            GUICtrlSetData($Edit_Num, $text)
        EndIf
    EndIf
    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then 
        _GUICtrlEdit_LineScroll($Edit_Num, 0, $iFirstVisMain - $iFirstVisNum)   
    EndIf
EndFunc

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Bowmore - this is looking good. The script doesn't stall and CPU is always low/zero, but it's on the far edge of what i'm able to understand at this point (nOOb). Maybe you can help me out...

When i ran it, i see '$g_iMainLineCount' was not declared. At first glance, i thought that was to be ($Edit_Main), but i see you already had that declared and i didn't see where it needs to be re-declared, so i just made it 'Local $g_iMainLineCount' at the top of the func and left it at that. This allows the script to run, but i'm still not sure what '$g_iMainLineCount' actually is.

Then we have:

If $iCount <> $g_iMainLineCount Then

$g_iMainLineCount = $iCount

This locks up my little brain because it says to me; if 'a' does not equal 'b' then 'b=a' which i see as being the same as; if 'a' does not equal 'b' then 'a=b'. My thinking is, if they don't equal, then why would you say they do? I'm wrong, i just don't why i'm wrong. I also tried dumping those 2 lines and the script *seems* to work the same (see below).

The only problem i see is that it doesn't work backwards, meaning the line numbers, once written, are never removed with the 'StringRegExpReplace'. What happens when you BACKSPACE is that $Edit_Num keeps redrawing endlessly.

The scrolling is cool! Basically 2 lines of code. Didn't know it could be done that efficiently.

Here's what i have...

#include <GUIConstants.au3>
#Include <GuiEdit.au3>
#Include <Misc.au3>

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)


AdlibEnable("_LineNum", 2)
;AdlibEnable("_ScrollSync", 12)


While 1

    $Msg = GUIGetMsg()

    Switch $Msg

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    
WEnd

Func _LineNum() ; line numbering
    ;Local $iCount = _GUICtrlEdit_GetLineCount ($Edit_Main)
    Local $g_iMainLineCount = _GUICtrlEdit_GetLineCount ($Edit_Main)
    Local $iNumCount = _GUICtrlEdit_GetLineCount ($Edit_Num)
    
    ;If $iCount <> $g_iMainLineCount Then
        ;$g_iMainLineCount = $iCount
        If $g_iMainLineCount > $iNumCount Then
            For $i = $iNumCount + 1 To $g_iMainLineCount
                _GUICtrlEdit_AppendText($Edit_Num, @CRLF & $i)
            Next
        ElseIf $g_iMainLineCount < $iNumCount Then
            $text = GUICtrlRead($Edit_Num)
            StringRegExpReplace($text,"(\r\n[0-9]*){" & $g_iMainLineCount - $iNumCount & "}^", "")
            GUICtrlSetData($Edit_Num, $text)
        EndIf
    ;EndIf
    
    ; sync scrolling
    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then
        _GUICtrlEdit_LineScroll($Edit_Num, 0, $iFirstVisMain - $iFirstVisNum)   
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

this is working so far...

#include <GUIConstants.au3>
#Include <GuiEdit.au3>
#Include <Misc.au3>

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)

Opt("TrayIconDebug", 1)

AdlibEnable("_LineNum", 2)
;AdlibEnable("_ScrollSync", 12)


While 1

    $Msg = GUIGetMsg()

    Switch $Msg

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    
WEnd

;#cs
Func _LineNum() ; line numbering
    ;Local $iCount = _GUICtrlEdit_GetLineCount($Edit_Main)
    ;Local $g_iMainLineCount ;= _GUICtrlEdit_GetLineCount ($Edit_Main)
    ;Local $iNumCount = _GUICtrlEdit_GetLineCount($Edit_Num)
    
    ;If _GUICtrlEdit_GetLineCount($Edit_Main) <> _GUICtrlEdit_GetLineCount($Edit_Num) Then
    ;_GUICtrlEdit_GetLineCount($Edit_Num) = _GUICtrlEdit_GetLineCount($Edit_Main)
    If _GUICtrlEdit_GetLineCount($Edit_Main) > _GUICtrlEdit_GetLineCount($Edit_Num) Then
        For $i = _GUICtrlEdit_GetLineCount($Edit_Num) + 1 To _GUICtrlEdit_GetLineCount($Edit_Main)
            _GUICtrlEdit_AppendText($Edit_Num, @CRLF & $i)
        Next
        #cs
            ElseIf _GUICtrlEdit_GetLineCount($Edit_Main) < _GUICtrlEdit_GetLineCount($Edit_Num) Then
            $text = GUICtrlRead($Edit_Num)
            StringRegExpReplace($text,"(\r\n[0-9]*){" & _GUICtrlEdit_GetLineCount($Edit_Main) - _GUICtrlEdit_GetLineCount($Edit_Num) & "}^", "")
            GUICtrlSetData($Edit_Num, $text)
            EndIf
        #ce
    ElseIf _GUICtrlEdit_GetLineCount($Edit_Main) < _GUICtrlEdit_GetLineCount($Edit_Num) Then
        $text = GUICtrlRead($Edit_Num)
        For $n = _GUICtrlEdit_GetLineCount($Edit_Main) To _GUICtrlEdit_GetLineCount($Edit_Num)
            $text = StringReplace($text, @CRLF & $n, '')
            ;Sleep(1)
        Next
        GUICtrlSetData($Edit_Num, $text)
    EndIf
    
    ; sync scrolling
    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine($Edit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine($Edit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then
        _GUICtrlEdit_LineScroll($Edit_Num, 0, $iFirstVisMain - $iFirstVisNum)
    EndIf
EndFunc   ;==>_LineNum

Share this post


Link to post
Share on other sites

Bowmore - this is looking good. The script doesn't stall and CPU is always low/zero, but it's on the far edge of what i'm able to understand at this point (nOOb). Maybe you can help me out...

When i ran it, i see '$g_iMainLineCount' was not declared. At first glance, i thought that was to be ($Edit_Main), but i see you already had that declared and i didn't see where it needs to be re-declared, so i just made it 'Local $g_iMainLineCount' at the top of the func and left it at that. This allows the script to run, but i'm still not sure what '$g_iMainLineCount' actually is.

Then we have:

If $iCount <> $g_iMainLineCount Then

$g_iMainLineCount = $iCount

This locks up my little brain because it says to me; if 'a' does not equal 'b' then 'b=a' which i see as being the same as; if 'a' does not equal 'b' then 'a=b'. My thinking is, if they don't equal, then why would you say they do? I'm wrong, i just don't why i'm wrong. I also tried dumping those 2 lines and the script *seems* to work the same (see below).

The only problem i see is that it doesn't work backwards, meaning the line numbers, once written, are never removed with the 'StringRegExpReplace'. What happens when you BACKSPACE is that $Edit_Num keeps redrawing endlessly.

The scrolling is cool! Basically 2 lines of code. Didn't know it could be done that efficiently.

Here's what i have...

#include <GUIConstants.au3>
#Include <GuiEdit.au3>
#Include <Misc.au3>

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)


AdlibEnable("_LineNum", 2)
;AdlibEnable("_ScrollSync", 12)


While 1

    $Msg = GUIGetMsg()

    Switch $Msg

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    
WEnd

Func _LineNum() ; line numbering
    ;Local $iCount = _GUICtrlEdit_GetLineCount ($Edit_Main)
    Local $g_iMainLineCount = _GUICtrlEdit_GetLineCount ($Edit_Main)
    Local $iNumCount = _GUICtrlEdit_GetLineCount ($Edit_Num)
    
    ;If $iCount <> $g_iMainLineCount Then
        ;$g_iMainLineCount = $iCount
        If $g_iMainLineCount > $iNumCount Then
            For $i = $iNumCount + 1 To $g_iMainLineCount
                _GUICtrlEdit_AppendText($Edit_Num, @CRLF & $i)
            Next
        ElseIf $g_iMainLineCount < $iNumCount Then
            $text = GUICtrlRead($Edit_Num)
            StringRegExpReplace($text,"(\r\n[0-9]*){" & $g_iMainLineCount - $iNumCount & "}^", "")
            GUICtrlSetData($Edit_Num, $text)
        EndIf
    ;EndIf
    
    ; sync scrolling
    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then
        _GUICtrlEdit_LineScroll($Edit_Num, 0, $iFirstVisMain - $iFirstVisNum)   
    EndIf
EndFunc

Replace

StringRegExpReplace($text,"(\r\n[0-9]*){" & $g_iMainLineCount - $iNumCount & "}^", "")

with

$text = stringleft($text, stringinstr($text,$g_iMainLineCount))

If you don't like AdLib then you could use the $EN_CHANGE nitification. I have just made an example here which might help.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

If $iCount <> $g_iMainLineCount Then

$g_iMainLineCount = $iCount

This locks up my little brain because it says to me; if 'a' does not equal 'b' then 'b=a' which i see as being the same as; if 'a' does not equal 'b' then 'a=b'.

Without actually looking at the fullscript, I have made an assumption on what is happening as it's a coding practice I use a lot myself.

To try and break it down, I'll use two examples:

Local $MouseNow
While 1
    $MouseNow = MouseGetPos(0) & ' x ' & MouseGetPos(1)
    ToolTip($MouseNow & @LF & TimerInit())
    Sleep(1)
WEndoÝ÷ ØÚ0ü¨º»§¶¬{¦¦W²¢íý[zØZ¶Ø^¶%¶*b±Ê'²Ö§¶®¥Ö­x½éðéíè§~æjب°j{L¢ë¦"¶*'«'¢×!jxu8^N)¬â¶+#ºËmêÞ²¨¹Æ§±ç­«b·lr쵩í+©u«báȬZn(y©pØZ¶%¶*[ºØÁì­ç!jx"ºw!¡û-¹÷ÛjÇ¢{azö«¦å{Mú2¬xÚ0Áì(ºWgßÛgyǬ±ªâ,ÛaÇ(ËZÛ©u«b®¶­sdÆö6Âb33c´Ö÷W6Tæ÷rÂb33c´Ö÷W6U&VÖVÖ&W ¥vÆR b33c´Ö÷W6Tæ÷rÒÖ÷W6TvWE÷2fײb33²b33²fײÖ÷W6TvWE÷2 bb33c´Ö÷W6Tæ÷rfÇC²fwC²b33c´Ö÷W6U&VÖVÖ&W"FVà FööÅFb33c´Ö÷W6Tæ÷rfײÄbfײFÖW$æB b33c´Ö÷W6U&VÖVÖ&W"Òb33c´Ö÷W6Tæ÷p VæD` 6ÆVW¥tVæ

Now as you can see in this example, the tooltip is NOT constantly updating - only when the mouse moves. Why? It's fairly simple. We are saving the mouse position in a "remember" variable so that we can compare it to see if/when it changes. Then when it does change, we update the remember variable with the new value to prepare for another comparison. Does that help to explain it a little better?

Share this post


Link to post
Share on other sites

If you don't like AdLib then you could use the $EN_CHANGE nitification.

That will work for the line count (work great in fact) but not for the scrolling. The best I've been able to discern, the only message being sent during the scrolling of an edit is WM_CTLCOLOREDIT. I guess you could hook that?

*Edit: Seems to work quite well actually.

#include <GUIConstants.au3>
#Include <GuiEdit.au3>
#Include <Misc.au3>

GUIRegisterMsg($WM_CTLCOLOREDIT, 'WM_CTLCOLOREDIT')

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
ConsoleWrite($Edit_Main & @CRLF)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)


While 1

    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_CTLCOLOREDIT($hWnd, $iMsg, $iWParam, $iLParam)
    If $iLParam = GUICtrlGetHandle($Edit_Main) Then
        Local $iCount = _GUICtrlEdit_GetLineCount ($Edit_Main)
        Local $iNumCount = _GUICtrlEdit_GetLineCount ($Edit_Num) - 2
        If $iCount <> $iNumCount Then
            Local $sNumContent = ''
            For $i = 1 To $iCount
                $sNumContent &= $i & @CRLF
            Next
            GUICtrlSetData($Edit_Num, $sNumContent & @CRLF)
        EndIf
        Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main)
        Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
        If $iFirstVisMain <> $iFirstVisNum Then
            _GUICtrlEdit_LineScroll($Edit_Num, 0, $iFirstVisMain - $iFirstVisNum)   
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc
Edited by Saunders

Share this post


Link to post
Share on other sites

That will work for the line count (work great in fact) but not for the scrolling. The best I've been able to discern, the only message being sent during the scrolling of an edit is WM_CTLCOLOREDIT. I guess you could hook that?

*Edit: Seems to work quite well actually.

That looks like a clever idea to me, I'd never heard of WM_CTLCOLOREDIT before, but perhaps it would be more obvious to use $EN_VSCROLL which is explained here.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I saw that, but it wouldn't work because it comes from the WM_COMMAND message which, for some reason, is not being fired off while moving the scrollbar (with the mouse).

Ah I see, I hadn't understood that. Seems a bit strange but not much we can do about that. Thanks Saunders.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

you guys are sharp!

Saunders - the last code you posted is looking very good! CPU rises to ~25% *only* if holding ENTER and after ~40+ lines. Same with BACKSPACE. That is quite acceptable to me since it's a condition that should never arise, but it's nice to know that the script won't bomb if it does :)

You may not have realized it, but your code fixed another problem i found which was the line numbers getting all screwed up if the script was run with a bunch of text already in the main edit control. It would re-write all/most of the line numbers like...

0123

4567

8901

2345

etc...

I added 1 line of code to cause a 3rd edit control to follow the others. Done! This is going too good now :P

I thank you ALL *very* much! I've been working on this with my very limited ability for way longer than i wanted/expected to.

Share this post


Link to post
Share on other sites

Bowmore - this is looking good. The script doesn't stall and CPU is always low/zero, but it's on the far edge of what i'm able to understand at this point (nOOb). Maybe you can help me out...

When i ran it, i see '$g_iMainLineCount' was not declared. At first glance, i thought that was to be ($Edit_Main), but i see you already had that declared and i didn't see where it needs to be re-declared, so i just made it 'Local $g_iMainLineCount' at the top of the func and left it at that. This allows the script to run, but i'm still not sure what '$g_iMainLineCount' actually is.

Sorry I should have posted my complete script. '$g_iMainLineCount' is a global variable used to save the line count between calls to _LineNum() so the we can check if a line has been added or deleted without having to run the complete function.

Then we have:

If $iCount <> $g_iMainLineCount Then

$g_iMainLineCount = $iCount

This locks up my little brain because it says to me; if 'a' does not equal 'b' then 'b=a' which i see as being the same as; if 'a' does not equal 'b' then 'a=b'. My thinking is, if they don't equal, then why would you say they do? I'm wrong, i just don't why i'm wrong. I also tried dumping those 2 lines and the script *seems* to work the same (see below).

This simple checks if the count has changed and if it has updates the global variable with the new value

The only problem i see is that it doesn't work backwards, meaning the line numbers, once written, are never removed with the 'StringRegExpReplace'. What happens when you BACKSPACE is that $Edit_Num keeps redrawing endlessly.

The 'StringRegExpReplace' was not working as I had intended so replaced with a simple loop,

with $g_iMainLineCount declared as a global variable at the top of the script this should work OK.

The scrolling is cool! Basically 2 lines of code. Didn't know it could be done that efficiently.

Complete script

#include <GUIConstants.au3>
#Include <GuiEdit.au3>
#Include <Misc.au3>

Global $g_iMainLineCount = 0 ; Keep a global count so we can check if it has changed

$Form1 = GUICreate("Form1", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$Edit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData(-1, "1")
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$Edit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Edit_Main = ' & $Edit_Main & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
GUICtrlCreateLabel("", 0, 164, 25, 11)
GUICtrlSetBkColor(-1, 0xC0DCC0)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)


AdlibEnable("_LineNum", 111)

While 1

    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
   
WEnd

Func _LineNum() ; line numbering
    Local $iCount = _GUICtrlEdit_GetLineCount ($Edit_Main)
    
    ;Check if the number of lines has changed in $Edit_Main
    ;since this function was last called
    If $iCount <> $g_iMainLineCount Then
        ;save the new count to the global variable
        $g_iMainLineCount = $iCount 
        Local $iNumCount = _GUICtrlEdit_GetLineCount ($Edit_Num)
        If $g_iMainLineCount > $iNumCount Then
            For $i = $iNumCount + 1 To $g_iMainLineCount
                _GUICtrlEdit_AppendText ($Edit_Num, @CRLF & $i)
            Next
        ElseIf $g_iMainLineCount < $iNumCount Then
            $text = GUICtrlRead($Edit_Num)
            For $i = $iNumCount To $g_iMainLineCount + 1 Step -1
                $text = StringReplace($text,@CRLF & $i,"")
            Next
            GUICtrlSetData($Edit_Num, $text)
        EndIf
    EndIf
    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($Edit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then 
        _GUICtrlEdit_LineScroll($Edit_Num, 0, $iFirstVisMain - $iFirstVisNum)   
    EndIf
EndFunc

Edit to script to replace StringRegExReplace with StringReplace

Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Very nice script.

Still works after small change:

AdlibEnable >>> AdlibRegister

I also make some celanup.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

#include <GUIConstants.au3>
#include <GuiEdit.au3>
#include <Misc.au3>

Global $g_iMainLineCount = 0 ; Keep a global count so we can check if it has changed
Global $_idEdit_Num , $_idEdit_Main

Example()

Func Example()
    Local $hGui = GUICreate("Example", 123, 176, 415, 239, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
    #forceref $hGui

    $_idEdit_Num = GUICtrlCreateEdit("", 0, 0, 25, 165, BitOR($ES_AUTOVSCROLL, $ES_READONLY), 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetData(-1, "1")
    GUICtrlSetBkColor(-1, 0xC0DCC0)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)

    $_idEdit_Main = GUICtrlCreateEdit("", 26, 0, 96, 175, -1, 0)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
    GUICtrlCreateLabel("", 0, 164, 25, 11)
    GUICtrlSetBkColor(-1, 0xC0DCC0)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)

    GUISetState(@SW_SHOW)

    AdlibRegister("_LineNum", 100)

    Local $Msg
    While 1

        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE
                Exit

        EndSwitch

    WEnd

EndFunc   ;==>Example

Func _LineNum() ; line numbering
    Local $iCount = _GUICtrlEdit_GetLineCount($_idEdit_Main)

    ;Check if the number of lines has changed in $_idEdit_Main
    ;since this function was last called
    If $iCount <> $g_iMainLineCount Then
        ;save the new count to the global variable
        $g_iMainLineCount = $iCount
        Local $iNumCount = _GUICtrlEdit_GetLineCount($_idEdit_Num)
        If $g_iMainLineCount > $iNumCount Then
            For $i = $iNumCount + 1 To $g_iMainLineCount
                _GUICtrlEdit_AppendText($_idEdit_Num, @CRLF & $i)
            Next
        ElseIf $g_iMainLineCount < $iNumCount Then
            Local $text = GUICtrlRead($_idEdit_Num)
            For $i = $iNumCount To $g_iMainLineCount + 1 Step -1
                $text = StringReplace($text, @CRLF & $i, "")
            Next
            GUICtrlSetData($_idEdit_Num, $text)
        EndIf
    EndIf

    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine($_idEdit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine($_idEdit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then
        _GUICtrlEdit_LineScroll($_idEdit_Num, 0, $iFirstVisMain - $iFirstVisNum)
    EndIf

EndFunc   ;==>_LineNum

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

Share this post


Link to post
Share on other sites

mLipok,

What are you doing?  This script is almost 7 years old.  If you want to retrofit old scripts and post them they should go in the examples section, not GH&S


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Indeed, my fault.
It was better to start in the "Example Scripts"
Sorry.

ps.
I did not intend to become a necroposter who asks questions in old topics.

I noticed this thread here, thanks to @Melba23.

So I corrected the script and I thought it would be worth it to put here instead of creating a new thread, which by the way has prevented the possible questions "Why is it not working?"

EDIT:

I would like to point out that ultimately I want to open a thread in the "Example Scripts", but after improving a few "inconveniences" in this script.

Or in this case my action was the right thing ?

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...