omzi Posted May 18, 2010 Posted May 18, 2010 (edited) First off, I'd like to thank you guys for being such a helpful community! This is the first time I've had to post here, in the past I've always been able to find what I need just browsing the forum. Sadly I can't for the life of me figure this out, and I know it's got to be something SOOO simple that I'm missing. What I want to do is update a label control as the user types into the input control. I know how to do this in javascript, hence the embedded window LOL. There's got to be a way to do this without embedding an IE window. I thought I figured it out but it just doesn't seem to work and I know I'm missing something in how I'm polling the control because it only updates when I click on the label. I've attached the entire code and if you run it you'll see how it works in javascript. I've put a note at the part I'm trying to get to work (down near the bottom). Thanks a lot in advance!!! PS. I don't think I made it clear, I'm basically trying to make it count how many characters are left out of 55 as they type expandcollapse popup#include <GUIConstantsEx.au3> #include<ie.au3> #include<windowsconstants.au3> #include<guiconstants.au3> $oIE = _IECreateEmbedded() $Gui = GUICreate("Character Counter", 600, 200, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 600, 100) $sHTML = '' $sHTML &= '<html>' & @CR $sHTML &= '<title>Character Counter</title>' & @CR $sHTML &= '<head>' & @CR $sHTML &= '<script language="Javascript" type="text/Javascript">' & @CR $sHTML &= 'function textCounter(field, countfield, maxlimit) {' & @CR $sHTML &= ' if (field.value.length > maxlimit)' & @CR $sHTML &= ' field.value =field.value.substring(0, maxlimit);' & @CR $sHTML &= ' else' & @CR $sHTML &= ' countfield.value = maxlimit - field.value.length;}' & @CR $sHTML &= '</script>' & @CR $sHTML &= '</head>' & @CR $sHTML &= '<body bgcolor=#f3f2f5>' & @CR $sHTML &= '<table><tr align="center" valign="top">' & @CR $sHTML &= ' <form name="form" id="form" method="post" action="">' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Item #' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="num" type="text" id="num" size="5" maxlength="6" tabindex ="1" />' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Category' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="cat" type="text" id="cat" size="5" maxlength="6" tabindex = "2" />' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Description' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="msg" size="61" wrap="physical" id="msg" onkeydown="textCounter(this.form.message, this.form.remLen,55);" onkeyup="textCounter(this.form.msg, this.form.remLen,55);" tabindex = "3" />' & @CR $sHTML &= ' <input name="remLen" type="text" id="remLen" value="55" size="2" maxlength="2" readonly tabindex = "-1" />' & @CR $sHTML &= ' characters still available.' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' </form>' & @CR $sHTML &= '</tr></table>' & @CR $sHTML &= '</body>' & @CR $sHTML &= '</html>' & @CR _IENavigate($oIE, "about:blank") _IEDocWriteHTML($oIE, $sHTML) _IEAction($oIE, "refresh") $oIE.document.body.scroll = "no" $Dum = GUICtrlCreateDummy() Dim $accels[1][2] = [["{ENTER}", $Dum]] GUISetAccelerators($accels) $remlen = GUICtrlCreateLabel("55", 275, 145, 25) ;<!== HERE $desc = GUICtrlCreateInput("test", 200, 120, 150) ;<!== HERE GUICtrlSetLimit(-1,55) GUISetState() Run("notepad.exe") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $desc ;<!== HERE GUICtrlSetData($remlen, 55-StringLen(GUICtrlRead($desc))) Case $Dum $oForm = _IEFormGetObjByName ($oIE, "form") $onum = _IEFormElementGetObjByName ($oForm, "num") $ocat = _IEFormElementGetObjByName ($oForm, "cat") $omsg = _IEFormElementGetObjByName ($oForm, "msg") $olen = _IEFormElementGetObjByName ($oForm, "remLen") $num = _IEFormElementGetValue($onum) _IEFormElementSetValue($onum, "") $cat = _IEFormElementGetValue($ocat) _IEFormElementSetValue($ocat, "") $msg = _IEFormElementGetValue($omsg) _IEFormElementSetValue($omsg, "") _IEFormElementSetValue($olen, "55") $data = $num&@TAB&$cat&@TAB&$msg&@CRLF WinActivate("[CLASS:Notepad]") ControlFocus("[CLASS:Notepad]", "", "Edit1") ControlCommand("[CLASS:Notepad]", "", "Edit1", "EditPaste", $data) WinActivate("Character Counter") Controlsend("Character Counter", "", "Internet Explorer_Server1", "{tab}{tab}") EndSwitch WEnd GUIDelete() Exit Edited May 18, 2010 by omzi
Herb191 Posted May 19, 2010 Posted May 19, 2010 Something like this? expandcollapse popup#include <GUIConstantsEx.au3> #include<ie.au3> #include<windowsconstants.au3> #include<guiconstants.au3> $oIE = _IECreateEmbedded() $Gui = GUICreate("Character Counter", 600, 200, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 600, 100) $sHTML = '' $sHTML &= '<html>' & @CR $sHTML &= '<title>Character Counter</title>' & @CR $sHTML &= '<head>' & @CR $sHTML &= '<script language="Javascript" type="text/Javascript">' & @CR $sHTML &= 'function textCounter(field, countfield, maxlimit) {' & @CR $sHTML &= ' if (field.value.length > maxlimit)' & @CR $sHTML &= ' field.value =field.value.substring(0, maxlimit);' & @CR $sHTML &= ' else' & @CR $sHTML &= ' countfield.value = maxlimit - field.value.length;}' & @CR $sHTML &= '</script>' & @CR $sHTML &= '</head>' & @CR $sHTML &= '<body bgcolor=#f3f2f5>' & @CR $sHTML &= '<table><tr align="center" valign="top">' & @CR $sHTML &= ' <form name="form" id="form" method="post" action="">' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Item #' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="num" type="text" id="num" size="5" maxlength="6" tabindex ="1" />' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Category' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="cat" type="text" id="cat" size="5" maxlength="6" tabindex = "2" />' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Description' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="msg" size="61" wrap="physical" id="msg" onkeydown="textCounter(this.form.message, this.form.remLen,55);" onkeyup="textCounter(this.form.msg, this.form.remLen,55);" tabindex = "3" />' & @CR $sHTML &= ' <input name="remLen" type="text" id="remLen" value="55" size="2" maxlength="2" readonly tabindex = "-1" />' & @CR $sHTML &= ' characters still available.' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' </form>' & @CR $sHTML &= '</tr></table>' & @CR $sHTML &= '</body>' & @CR $sHTML &= '</html>' & @CR _IENavigate($oIE, "about:blank") _IEDocWriteHTML($oIE, $sHTML) _IEAction($oIE, "refresh") $oIE.document.body.scroll = "no" $Dum = GUICtrlCreateDummy() Dim $accels[1][2] = [["{ENTER}", $Dum]] GUISetAccelerators($accels) $remlen = GUICtrlCreateLabel("55", 275, 145, 25) ;<!== HERE $desc = GUICtrlCreateInput("test", 200, 120, 150) ;<!== HERE GUICtrlSetLimit(-1,55) GUISetState() Run("notepad.exe") While 1 $desc_input = GUICtrlRead($desc) Select Case 55-StringLen(GUICtrlRead($desc) <> $desc_input) GUICtrlSetData($remlen, 55-StringLen(GUICtrlRead($desc))) EndSelect $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Dum $oForm = _IEFormGetObjByName ($oIE, "form") $onum = _IEFormElementGetObjByName ($oForm, "num") $ocat = _IEFormElementGetObjByName ($oForm, "cat") $omsg = _IEFormElementGetObjByName ($oForm, "msg") $olen = _IEFormElementGetObjByName ($oForm, "remLen") $num = _IEFormElementGetValue($onum) _IEFormElementSetValue($onum, "") $cat = _IEFormElementGetValue($ocat) _IEFormElementSetValue($ocat, "") $msg = _IEFormElementGetValue($omsg) _IEFormElementSetValue($omsg, "") _IEFormElementSetValue($olen, "55") $data = $num&@TAB&$cat&@TAB&$msg&@CRLF WinActivate("[CLASS:Notepad]") ControlFocus("[CLASS:Notepad]", "", "Edit1") ControlCommand("[CLASS:Notepad]", "", "Edit1", "EditPaste", $data) WinActivate("Character Counter") Controlsend("Character Counter", "", "Internet Explorer_Server1", "{tab}{tab}") EndSwitch WEnd GUIDelete() Exit
omzi Posted May 20, 2010 Author Posted May 20, 2010 This wasn't quite right, because the statement is always true so it just refreshes constantly (and makes it flicker wierd). However it did put me on the right track! I didn't even think about making a condition in that tight loop to see if there was a change in what was in the input box. What I did was set var $char to 0, then check if it matches how many characters are in the input box, it will not match at first so it triggers then writes the correct amount so it won't trigger again until it changes. I marked the change for anyone else who may run into this problem. expandcollapse popup#include <GUIConstantsEx.au3> #include<ie.au3> #include<windowsconstants.au3> #include<guiconstants.au3> $oIE = _IECreateEmbedded() $Gui = GUICreate("Character Counter", 600, 200, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 600, 100) $sHTML = '' $sHTML &= '<html>' & @CR $sHTML &= '<title>Character Counter</title>' & @CR $sHTML &= '<head>' & @CR $sHTML &= '<script language="Javascript" type="text/Javascript">' & @CR $sHTML &= 'function textCounter(field, countfield, maxlimit) {' & @CR $sHTML &= ' if (field.value.length > maxlimit)' & @CR $sHTML &= ' field.value =field.value.substring(0, maxlimit);' & @CR $sHTML &= ' else' & @CR $sHTML &= ' countfield.value = maxlimit - field.value.length;}' & @CR $sHTML &= '</script>' & @CR $sHTML &= '</head>' & @CR $sHTML &= '<body bgcolor=#f3f2f5>' & @CR $sHTML &= '<table><tr align="center" valign="top">' & @CR $sHTML &= ' <form name="form" id="form" method="post" action="">' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Item #' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="num" type="text" id="num" size="5" maxlength="6" tabindex ="1" />' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Category' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="cat" type="text" id="cat" size="5" maxlength="6" tabindex = "2" />' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' <td>' & @CR $sHTML &= ' Description' & @CR $sHTML &= ' <br />' & @CR $sHTML &= ' <input name="msg" size="61" wrap="physical" id="msg" onkeydown="textCounter(this.form.message, this.form.remLen,55);" onkeyup="textCounter(this.form.msg, this.form.remLen,55);" tabindex = "3" />' & @CR $sHTML &= ' <input name="remLen" type="text" id="remLen" value="55" size="2" maxlength="2" readonly tabindex = "-1" />' & @CR $sHTML &= ' characters still available.' & @CR $sHTML &= ' </td>' & @CR $sHTML &= ' </form>' & @CR $sHTML &= '</tr></table>' & @CR $sHTML &= '</body>' & @CR $sHTML &= '</html>' & @CR _IENavigate($oIE, "about:blank") _IEDocWriteHTML($oIE, $sHTML) _IEAction($oIE, "refresh") $oIE.document.body.scroll = "no" $Dum = GUICtrlCreateDummy() Dim $accels[1][2] = [["{ENTER}", $Dum]] GUISetAccelerators($accels) $char = 0 ;<!== NEW $remlen = GUICtrlCreateLabel("55", 275, 145, 25) ;<!== HERE $desc = GUICtrlCreateInput("test", 200, 120, 150) ;<!== HERE GUICtrlSetLimit(-1,55) GUISetState() Run("notepad.exe") While 1 if StringLen(GUICtrlRead($desc)) <> $char Then ;<!== NEW GUICtrlSetData($remlen, 55-StringLen(GUICtrlRead($desc))) ;<!== NEW $char = StringLen(GUICtrlRead($desc)) ;<!== NEW EndIf ;<!== NEW $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Dum $oForm = _IEFormGetObjByName ($oIE, "form") $onum = _IEFormElementGetObjByName ($oForm, "num") $ocat = _IEFormElementGetObjByName ($oForm, "cat") $omsg = _IEFormElementGetObjByName ($oForm, "msg") $olen = _IEFormElementGetObjByName ($oForm, "remLen") $num = _IEFormElementGetValue($onum) _IEFormElementSetValue($onum, "") $cat = _IEFormElementGetValue($ocat) _IEFormElementSetValue($ocat, "") $msg = _IEFormElementGetValue($omsg) _IEFormElementSetValue($omsg, "") _IEFormElementSetValue($olen, "55") $data = $num&@TAB&$cat&@TAB&$msg&@CRLF WinActivate("[CLASS:Notepad]") ControlFocus("[CLASS:Notepad]", "", "Edit1") ControlCommand("[CLASS:Notepad]", "", "Edit1", "EditPaste", $data) WinActivate("Character Counter") Controlsend("Character Counter", "", "Internet Explorer_Server1", "{tab}{tab}") EndSwitch WEnd GUIDelete() Exit And thanks again Herb191. I really wouldn't of thought of this if it wasn't for you
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