dreamzboy Posted March 18, 2015 Posted March 18, 2015 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! expandcollapse popup; 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
jaberwacky Posted March 19, 2015 Posted March 19, 2015 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) expandcollapse popup; 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 Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
dreamzboy Posted March 19, 2015 Author Posted March 19, 2015 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
jaberwacky Posted March 19, 2015 Posted March 19, 2015 just replace it with 3 Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
Moderators Melba23 Posted March 19, 2015 Moderators Posted March 19, 2015 jaberwacky & dreamzboy,I would do it this way: Case $button $count = ControlCommand("Host Count", "", $hostEdit, "GetLineCount", "") GUICtrlSetData($label, $count)M23 jaberwacky 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jaberwacky Posted March 19, 2015 Posted March 19, 2015 Op, please mark #5 as solved. /thread Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
dreamzboy Posted March 19, 2015 Author Posted March 19, 2015 (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) Edited March 19, 2015 by dreamzboy
Moderators Solution Melba23 Posted March 19, 2015 Moderators Solution Posted March 19, 2015 dreamzboy,Sorry about that - I based my response on jaberwacky's code. How about this? expandcollapse popup#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 ;==>ExampleBetter? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
dreamzboy Posted March 19, 2015 Author Posted March 19, 2015 You are brilliant! I wish I have 1/4 of your intelligence. Thanks to both of you.
kylomas Posted March 24, 2015 Posted March 24, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now