dreamzboy

Real-time Line Counter

10 posts in this topic

I have an edit box that I wanted to keep tabs of the line number in real-time.  For an example, if a user enter 3 lines, the counter should update as soon as the user hit "Enter" after the 3rd entry.  I managed to do it but it's not real-time.  Program would hung or slow to response after I hit the "Configuration" button.

Many thanks!

; Testing Host Count

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <StaticConstants.au3>

Example()

Func Example()
    Local $hostLabel, $hostEdit, $button, $msg, $count, $hostname
    GUICreate("Host Count") ; will create a dialog box that when displayed is centered

    $hostLabel = GUICtrlCreateLabel ("Hostname", 10, 10, 120, 20)
    $hostEdit = GUICtrlCreateEdit ("", 10, 40, 200, 80)
    $button = GUICtrlCreateButton ("Configure", 20, 140, 120, 30)

    GUISetState() ; will display an  dialog box with 1 checkbox

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        $hostname = StringRegExp (GUICtrlRead ($hostEdit), '\V\S+', 3)
        $count = UBound ($hostname)
        sleep (500)
        GUICtrlCreateLabel ($count, 200, 10, 10, 20, $SS_RIGHT)
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $button
                MsgBox (0, "Count", "The count is " & $count)
                #cs
                $hostname = StringRegExp (GUICtrlRead ($hostEdit), '\V\S+', 3)
                $count = UBound ($hostname)
                GUICtrlCreateLabel ($count, 200, 10, 10, 20, $SS_RIGHT)
                #ce
        EndSelect
    WEnd
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites



This is the best I can do.  I'm sure there is a better way, so stick around.  I'm *sure* that someone will see my post and be inspired to do a better job.  8)

; Testing Host Count

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <StaticConstants.au3>

Example()

Func Example()
    GUICreate("Host Count")

    Local Const $hostLabel = GUICtrlCreateLabel("Hostname", 10, 10, 120, 20)
        
    Local Const $label = GUICtrlCreateLabel('0', 200, 10, 30, 20, $SS_RIGHT)
    
    Local Const $hostEdit = GUICtrlCreateEdit("", 10, 40, 200, 80)
    
    Local Const $button = GUICtrlCreateButton("Configure", 20, 140, 120, 30)

    GUISetState(@SW_SHOWNORMAL)

    Local $count, $hostname
    
    Do              
        Switch GUIGetMsg()
            Case $button
                $hostname = StringRegExp(GUICtrlRead($hostEdit), "(*ANY)", $STR_REGEXPARRAYGLOBALMATCH)
                
                $count = (UBound($hostname) - 1) / 2
                
                GUICtrlSetData($label, $count)
                
            Case $GUI_EVENT_CLOSE
                ExitLoop                
        EndSwitch
    Until False
EndFunc

Share this post


Link to post
Share on other sites

Thank you for the quick response.  I tried running your code but came up with undeclared variable error:

C:\Users\nguyenk\Documents\AutoIT\RxG\test5.au3(20,91) : WARNING: $STR_REGEXPARRAYGLOBALMATCH: possibly used before declaration.
                $hostname = StringRegExp(GUICtrlRead($hostEdit), "(*ANY)", $STR_REGEXPARRAYGLOBALMATCH)
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\nguyenk\Documents\AutoIT\RxG\test5.au3(20,91) : ERROR: $STR_REGEXPARRAYGLOBALMATCH: undeclared global variable.
                $hostname = StringRegExp(GUICtrlRead($hostEdit), "(*ANY)", $STR_REGEXPARRAYGLOBALMATCH)
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\nguyenk\Documents\AutoIT\RxG\test5.au3 - 1 error(s), 1 warning(s)
!>18:06:06 AU3Check ended. Press F4 to jump to next error.rc:2
>Exit code: 2    Time: 0.517

Share this post


Link to post
Share on other sites

jaberwacky & dreamzboy,

I would do it this way: ;)

Case $button
    $count = ControlCommand("Host Count", "", $hostEdit, "GetLineCount", "")
    GUICtrlSetData($label, $count)
M23
1 person likes this

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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Maybe I'm missing something but that's not real-time.  The count only update once you hit the $button.  What I'm looking for is a line counter similar to the Scite Editor where it shows the number of lines at the bottom of the status bar as you type.  It should show the number of lines even before you hit the button.

My current code work great counting only the number of entries which is what I wanted instead of empty lines.  The problem is that it's not real-time.  It doesn't show the entry number until you hit the $button.

Case $msg = $button
                $hostname = StringRegExp (GUICtrlRead ($hostEdit), '\V\S+', 3)
                $count = UBound ($hostname)
                GUICtrlSetData ($countLabel, $count)

 counter.jpg

Edited by dreamzboy

Share this post


Link to post
Share on other sites

dreamzboy,

Sorry about that - I based my response on jaberwacky's code. How about this? ;)

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <StaticConstants.au3>

Example()

Func Example()
    GUICreate("Host Count")

    Local $hostLabel = GUICtrlCreateLabel("Hostname", 10, 10, 120, 20)
    Local $label = GUICtrlCreateLabel('0', 200, 10, 30, 20, $SS_RIGHT)
    Local $hostEdit = GUICtrlCreateEdit("", 10, 40, 200, 80)
    Local $button = GUICtrlCreateButton("Configure", 20, 140, 120, 30)

    GUISetState()

    Local $count, $iCurrentCount = 0

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch

        ; Get current line count
        $count = ControlCommand("Host Count", "", $hostEdit, "GetLineCount", "")
        ; If not what is stored
        If $count <> $iCurrentCount Then
            ; Reset label
            GUICtrlSetData($label, $count)
            ; Store new value
            $iCurrentCount = $count
        EndIf

    WEnd

EndFunc   ;==>Example
Better? :)

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

You are brilliant!  I wish I have 1/4 of your intelligence.  :thumbsup:

Thanks to both of you.

Share this post


Link to post
Share on other sites

 You are brilliant! 

 

...and then some...

No shit, you learn something new every day, thanks M23...


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

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

  • Similar Content

    • UEZ
      By UEZ
      Since monoceres has released 
      I'm searching for a way to map the 2D image of the earth to a 3D sphere with rotation.
       
      Here the result (after 9 years!) as a non realistic physical animation:
       ==> 
       
      Due to the fact that AutoIt / GDI+ are not that fast I couldn't add a moon animation additionally.
       
      Thanks to one of Eukalyptus' code to pointing me to the right direction. U rock man. 
       
      Source code extract only - not working because of missing binary data (images):
      ;coded by UEZ build 2017-02-25 #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Icons\au3.ico") #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /pe /rm #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hGUI, $iFPS = 0, $iShowFPS = 0, $bExit Global Const $iW = 800, $iH = 500, $iWh = $iW / 2, $iHh = $iH / 2, $sTitle = "GDI+ Rotating Earth coded by UEZ 2017" Global Const $fPi = ACos(-1), $fRad = $fPi / 180, $fDeg = 180 / $fPi AutoItSetOption("GUIOnEventMode", 1) GDIPlus_RotatingEarth() AutoItSetOption("GUIOnEventMode", 0) _GDIPlus_Shutdown() Func GDIPlus_RotatingEarth() $bExit = False $hGUI = GUICreate($sTitle, $iW, $iH) ;, 0, 0, $WS_POPUP) GUISetState(@SW_SHOW, $hGUI) ;~ GUISetCursor(16, 1) ;create canvas elements Local Const $hDC = _WinAPI_GetDC($hGUI) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local Const $hDC_backbuffer = _WinAPI_CreateCompatibleDC($hDC) Local Const $DC_obj = _WinAPI_SelectObject($hDC_backbuffer, $hHBitmap) Local Const $hCanvas = _GDIPlus_GraphicsCreateFromHDC($hDC_backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hCanvas, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local Const $hBrush_Clr = _GDIPlus_BrushCreateSolid(0xFF000000), _ $hBrush_FPS = _GDIPlus_BrushCreateSolid(0xFFF0F0F0), _ $hFormat_FPS = _GDIPlus_StringFormatCreate(), _ $hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial"), _ $hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 8), _ $tLayout_FPS = _GDIPlus_RectFCreate(0, 0, 60, 16), _ $hImage_Earth = _GDIPlus_BitmapCreateFromMemory(_Earth()), _ $hImage_Galaxy = _GDIPlus_BitmapCreateFromMemory(_Galaxy()), _ $hMatrix = _GDIPlus_MatrixCreate(), $hPath = _GDIPlus_PathCreate() Local $aDim = _GDIPlus_ImageGetDimension($hImage_Earth) Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hImage_Earth) _GDIPlus_GraphicsDrawStringEx($hGfx, "Coded by UEZ 2017 ;-)", $hFont_FPS, _GDIPlus_RectFCreate(0, $aDim[1] / 2 - 4, 120, 12), $hFormat_FPS, $hBrush_FPS) _GDIPlus_ImageDispose($hGfx) Local Const $hTexture_Earth = _GDIPlus_TextureCreate($hImage_Earth) DllCall($__g_hGDIPDll, "int", "GdipTranslateTextureTransform", "ptr", $hTexture_Earth, "float", -200, "float", 0, "long", 0) Local $iDiameter = $aDim[0] < $aDim[1] ? $aDim[0] : $aDim[1], _ $iDiameter2 = $iDiameter / 2, _ $fDX = ($iW - $iDiameter) / 2, $fDY = ($iH - $iDiameter) / 2 _GDIPlus_PathAddEllipse($hPath, $fDX - 1, $fDY - 1, $iDiameter + 2, $iDiameter + 2) Local Const $hBrush = _GDIPlus_PathBrushCreateFromPath($hPath) _GDIPlus_PathBrushSetCenterColor($hBrush, 0x04000008) _GDIPlus_PathBrushSetCenterPoint($hBrush, $fDX + $iDiameter2 + 1, $fDY + $iDiameter2 + 1) _GDIPlus_PathBrushSetSurroundColor($hBrush, 0xF0000000) _GDIPlus_PathBrushSetGammaCorrection($hBrush, 1) _GDIPlus_PathBrushSetFocusScales($hBrush, 0.5, 0.5) $iFPS = 0 GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit_About") AdlibRegister("CalcFPS", 1000) Local $fScale, $fTmp, $iStep = 2 ;the higher $iStep is the faster the animation & lower the quality. Do ;~ DllCall($__g_hGDIPDll, "int", "GdipFillRectangle", "handle", $hCanvas, "handle", $hBrush_Clr, "float", 0, "float", 0, _ ;~ "float", $iW, "float", $iH) ;erase canvas background ;~ _WinAPI_BitBlt($hDC_backbuffer, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $BLACKNESS) _GDIPlus_GraphicsDrawImageRect($hCanvas, $hImage_Galaxy, 0, 0, $iW, $iH) DllCall($__g_hGDIPDll, "int", "GdipTranslateTextureTransform", "ptr", $hTexture_Earth, "float", 0.75, "float", 0, "long", 0) For $i = 1 To $iDiameter2 Step $iStep $fScale = 1 + $i / $iDiameter2 _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0) _GDIPlus_MatrixTranslate($hMatrix, $fDX + $iDiameter2, $fDY + $iDiameter2) _GDIPlus_MatrixScale($hMatrix, $fScale, $fScale) _GDIPlus_MatrixTranslate($hMatrix, -$iDiameter2, -$iDiameter2) _GDIPlus_GraphicsSetTransform($hCanvas, $hMatrix) DllCall($__g_hGDIPDll, "int", "GdipFillEllipse", "handle", $hCanvas, "handle", $hTexture_Earth, _ "float", $i, "float", $i, "float", $iDiameter - $i * 2, "float", $iDiameter - $i * 2) Next _GDIPlus_MatrixSetElements($hMatrix, 1, 0, 0, 1, 0, 0) _GDIPlus_GraphicsSetTransform($hCanvas, $hMatrix) _GDIPlus_GraphicsFillRect($hCanvas, $fDX, $fDY, $iDiameter, $iDiameter, $hBrush) _GDIPlus_GraphicsDrawStringEx($hCanvas, "FPS: " & $iShowFPS, $hFont_FPS, $tLayout_FPS, $hFormat_FPS, $hBrush_FPS) ;draw background message text _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hDC_backbuffer, 0, 0, $SRCCOPY) ;blit drawn bitmap to GUI $iFPS += 1 If $bExit Then ExitLoop Until Not Sleep(10) AdlibUnRegister("CalcFPS") ;release resources _GDIPlus_BrushDispose($hBrush) _GDIPlus_PathDispose($hPath) _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_ImageDispose($hImage_Earth) _GDIPlus_ImageDispose($hImage_Galaxy) _GDIPlus_BrushDispose($hTexture_Earth) _GDIPlus_FontDispose($hFont_FPS) _GDIPlus_FontFamilyDispose($hFamily_FPS) _GDIPlus_StringFormatDispose($hFormat_FPS) _GDIPlus_BrushDispose($hBrush_Clr) _GDIPlus_BrushDispose($hBrush_FPS) _GDIPlus_GraphicsDispose($hCanvas) _WinAPI_SelectObject($hDC_backbuffer, $DC_obj) _WinAPI_DeleteDC($hDC_backbuffer) _WinAPI_DeleteObject($hHBitmap) _WinAPI_ReleaseDC($hGUI, $hDC) GUIDelete($hGUI) EndFunc ;==>GDIPlus_RotatingEarth Func _Exit_About() $bExit = True EndFunc ;==>_Exit_About Func CalcFPS() ;display FPS $iShowFPS = $iFPS $iFPS = 0 EndFunc ;==>CalcFPS ;Code below was generated by: 'File to Base64 String' Code Generator v1.20 Build 2016-12-01 ...  
      Download: Rotating Earth v1.7.au3
      In line 92 you can modify the $iStep variable -> the higher $iStep is the faster the animation & lower the quality.
       
      So long...
    • scintilla4evr
      By scintilla4evr
      Simple UDF for creating animations in GDI+
       
      If you want to see more "experimental" features, go to GitHub.
    • scintilla4evr
      By scintilla4evr
      Hello! I've been working on this UDF for some time, but when I read Seeking "kinetic typography" capability in au3 topic, I decided to share it. This UDF brings some functions for creating animations in GDI+ without worrying about rendering or calculating.

      Features:
      Adding basic shapes (rectangle, ellipse) and text Animating object properties (like position or size) Animatable transformations (translate, rotate, scale) Double-buffering Rendering to a window or GUI control Enjoy!
      Motion Graphics UDF
    • UEZ
      By UEZ
      Here a little Outro for all the animation lovers which I created when I played around with spheres.
      Download:    Sphere Outro.7z     --=> 7-Zip archive
       

       
      Credits:
      Eukalyptus (GDIPlusEx.au3 -> don't search for it because it is not released for the public )
      wakillon & TitchySID.dll creator
       
      If it is too slow reduce the stars in line 77 (-=> $iStars)
      If you cannot see the fade in/out text change in line 152 the font name from "Plantagenet Cherokee" to "Times New Roman"!
       

    • UEZ
      By UEZ
      Here a version of a splash text variant using GDI+.




       
      Requires AutoIt v3.3.12.0 or higher! 
       
      Source code download:
       
      UDF: _SplashTextEx.au3 (previous downloads: 135) 
      Example: Example1.au3 (previous downloads: 127)
       
      Might be useful for someone...
       
       
      Please report any bugs.