jfcby Posted May 26, 2010 Posted May 26, 2010 (edited) Hello, I'm trying to limit the characters in a GUICtrlCreateInput control. When I use GUICtrlSetLimit it only works when the charactes or numbers are being typed in. How can I set the character limit when I use GUICtrlSetData to change the input text? #include <GUIConstantsEx.au3> Example() Func Example() Local $msg GUICreate("My GUI limit input 3 chars") ; will create a dialog box that when displayed is centered GUICtrlCreateInput("", 10, 20) GUICtrlSetLimit(-1, 3) ; to limit the entry to 3 chars GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example Thank you for your help, jfcby Edited May 26, 2010 by jfcby PoojaKrishna 1 Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****
AlmarM Posted May 26, 2010 Posted May 26, 2010 #include <GUIConstantsEx.au3> Example() Func Example() Local $msg GUICreate("My GUI limit input 3 chars") ; will create a dialog box that when displayed is centered $Input = GUICtrlCreateInput("", 10, 20) GUICtrlSetLimit(-1, 3) ; to limit the entry to 3 chars $Button = GUICtrlCreateButton("Click me", 10, 100, 100, 20) GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case -3 Exit Case $Button $NewText = InputBox(Default, "Enter new texts.") If StringLen($NewText) > 3 Then MsgBox(16, Default, "Text cannot be longer as 3 characters!") Else GUICtrlSetData($Input, $NewText) EndIf EndSwitch WEnd EndFunc ;==>Example Check with an If statement? Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.
Affe Posted May 26, 2010 Posted May 26, 2010 Hello, I'm trying to limit the characters in a GUICtrlCreateInput control. When I use GUICtrlSetLimit it only works when the charactes or numbers are being typed in. How can I set the character limit when I use GUICtrlSetData to change the input text? #include <GUIConstantsEx.au3> Example() Func Example() Local $msg GUICreate("My GUI limit input 3 chars") ; will create a dialog box that when displayed is centered GUICtrlCreateInput("", 10, 20) GUICtrlSetLimit(-1, 3) ; to limit the entry to 3 chars GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example Thank you for your help, jfcby If you're setting the data via the program, you have a couple of choices: 1) Use statements to validate the data being sent before sending (StringLen($string) will return the length) 2) Truncate the data sent (StringLeft($string, 3) will return the first 3 characters, StringRight() will do the right side) [center][/center]
Moderators Melba23 Posted May 26, 2010 Moderators Posted May 26, 2010 jfcby,How can I set the character limit when I use GUICtrlSetData to change the input text?Use GUICtrlSetData($hInput, StringLeft($sData, 3)). 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
jfcby Posted May 26, 2010 Author Posted May 26, 2010 Use GUICtrlSetData($hInput, StringLeft($sData, 3)). Melba23 thank you for the code it works great. Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****
jfcby Posted May 26, 2010 Author Posted May 26, 2010 I would like to thank each one for responding to my post. You were very helpful. The answer now is so obvious but at the time I had no clue where to begin. Thank you, jfcby Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****
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