merriman Posted July 11, 2006 Share Posted July 11, 2006 Hi Is there a way to count the number of characters a user types into a Edit control, at the time the user types them. I would like to set a variable for the maximum number characters allowed and decrement it has the user types into the edit control. I am using it to send a SMS from a website to a mobile phone, and the maximum number of character allowed is 163. Would appreciate some advice Best Regards Merriman Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 11, 2006 Moderators Share Posted July 11, 2006 (edited) StringLen(GUICtrlRead($EditControl))? Edit: Here's an example because I was bored:expandcollapse popup#include <guiconstants.au3> Opt('GUIOnEventMode', 1) $Main = GUICreate('Edit Test', 200, 270) $Edit = GUICtrlCreateEdit('', 10, 10, 180, 190) $Label = GUICtrlCreateLabel(0, 10, 205, 180, 20, $ES_READONLY) $Submit = GUICtrlCreateButton('Send', 30, 225, 60, 30) $Clear = GUICtrlCreateButton('Clear', 100, 225, 60, 30) GUISetOnEvent($GUI_EVENT_CLOSE, '_Event_Handler', $Main) GUICtrlSetOnEvent($Submit, '_Event_Handler') GUICtrlSetOnEvent($Clear, '_Event_Handler') GUISetState() AdlibEnable('_CheckEditLength', 10) While 1 Sleep(20000) WEnd Func _Event_Handler() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE Exit Case $Submit Local $GCTRLRead = GUICtrlRead($Edit) If StringLen($GCTRLRead) < 164 Then ;do something you would do to send it Else MsgBox(64, 'Info:', 'Please check your length, you are only allowed 163 characters.') EndIf Case $Clear GUICtrlSetData($Edit, '') EndSwitch EndFunc Func _CheckEditLength() Local $GCTRLReadEdit = GUICtrlRead($Edit) Local $GCTRLReadLabel = GUICtrlRead($Label) If StringLen($GCTRLReadEdit) <> Int($GCTRLReadLabel) Then GUICtrlSetData($Label, StringLen($GCTRLReadEdit)) EndIf If StringLen($GCTRLReadEdit) > 163 Then GUICtrlSetData($Edit, StringLeft($GCTRLReadEdit, 163)) GUICtrlSetData($Label, StringLen(GUICtrlRead($Edit))) EndIf EndFuncEdit2: Replaced a > with <> Edited July 11, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Skruge Posted July 11, 2006 Share Posted July 11, 2006 How about this?GUICtrlSetLimit($EditControl,163) ; to limit the entry to 163 chars [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 11, 2006 Moderators Share Posted July 11, 2006 How about this?GUICtrlSetLimit($EditControl,163) ; to limit the entry to 163 charsI can't tell you how many times I forget about that function... obviously that's the proper way! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
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