Sign in to follow this  
Followers 0
jfcby

[Resolved] GUICtrlCreateInput Limit Characters

6 posts in this topic

#1 ·  Posted (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 by 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 ****

Share this post


Link to post
Share on other sites



#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.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

jfcby,

How can I set the character limit when I use GUICtrlSetData to change the input text?

Use GUICtrlSetData($hInput, StringLeft($sData, 3)). :mellow:

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

Use GUICtrlSetData($hInput, StringLeft($sData, 3)). :mellow:

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 ****

Share this post


Link to post
Share on other sites

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 ****

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
Sign in to follow this  
Followers 0