Jump to content

GUI Input just for one letter (no numbers or special characters). How???


Recommended Posts

I'm from Brasil and I don't speak English very well - sorry.

I made some GUI Input and would like 4 of these GUI Input accept only letters - not numbers (uppercase letters = A,B,C,D,..,Z) - Something like $ES_LETTERS instead of $ES_NUMBER.

What I have to do? Tried Search and Google a lot and nothing....

Thanks for all.

$LinhaINPUT = GUICtrlCreateInput("3", 107, 30, 25, 21, BitOR($ES_CENTER,$ES_NUMBER))   ; THIS ACCEPT ONLY 1 NUMBER
$OrdemINPUT = GUICtrlCreateInput("B", 235, 62, 25, 21, BitOR($ES_CENTER,$ES_UPPERCASE))  ; THIS MUST ACCEPT ONLY 1 LETTER (A,B,C,...,Z)
GUICtrlSetLimit(-1, 1)
$HistoricoINPUT = GUICtrlCreateInput("H", 171, 94, 25, 21, BitOR($ES_CENTER,$ES_UPPERCASE))  ; THIS MUST ACCEPT ONLY 1 LETTER (A,B,C,...,Z)
GUICtrlSetLimit(-1, 1)
$StatusOrdemINPUT = GUICtrlCreateInput("F", 219, 126, 25, 21, BitOR($ES_CENTER,$ES_UPPERCASE))  ; THIS MUST ACCEPT ONLY 1 LETTER (A,B,C,...,Z)
GUICtrlSetLimit(-1, 1)
$StatusDetalhadoINPUT = GUICtrlCreateInput("G", 219, 158, 25, 21, BitOR($ES_CENTER,$ES_UPPERCASE))  ; THIS MUST ACCEPT ONLY 1 LETTER (A,B,C,...,Z)
GUICtrlSetLimit(-1, 1)
$PastaTrabalhoINPUT = GUICtrlCreateInput("INSTRUMENTACAO", 203, 190, 206, 21)
$CaminhoPlanilhaINPUT = GUICtrlCreateInput("", 24, 224, 385, 21)
Link to comment
Share on other sites

Hi, maybe you could use a Combo box with the control style $CBS_DROPDOWNLIST instead of an input box.

This way the user can only select what's in the combo box via a key press or the dropdown menu.

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

Example()

Func Example()
    Local $msg, $LinhaINPUT, $OrdemINPUT, $HistoricoINPUT,  $StatusOrdemINPUT, $StatusDetalhadoINPUT
    GUICreate("Combo $CBS_DROPDOWNLIST")  ; will create a dialog box that when displayed is centered
    $LinhaINPUT = GUICtrlCreateCombo("", 107, 30, 40, 21, $CBS_DROPDOWNLIST)   ; THIS ACCEPT ONLY 1 NUMBER
    _SetComboData($LinhaINPUT, "3", 1)
    $OrdemINPUT = GUICtrlCreateCombo("", 235, 62, 40, 21, $CBS_DROPDOWNLIST)  ; THIS MUST ACCEPT ONLY 1 LETTER (A,B,C,...,Z)
    _SetComboData($OrdemINPUT, "B")
    $HistoricoINPUT = GUICtrlCreateCombo("", 171, 94, 40, 21, $CBS_DROPDOWNLIST)  ; THIS MUST ACCEPT ONLY 1 LETTER (A,B,C,...,Z)
    _SetComboData($HistoricoINPUT, "H")
    $StatusOrdemINPUT = GUICtrlCreateCombo("", 219, 126, 40, 21, $CBS_DROPDOWNLIST)  ; THIS MUST ACCEPT ONLY 1 LETTER (A,B,C,...,Z)
    _SetComboData($StatusOrdemINPUT, "F")
    $StatusDetalhadoINPUT = GUICtrlCreateCombo("", 219, 158, 40, 21, $CBS_DROPDOWNLIST)  ; THIS MUST ACCEPT ONLY 1 LETTER (A,B,C,...,Z)
    _SetComboData($StatusDetalhadoINPUT, "G")
    GUISetState()

    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc


; $iCID: Ctrl ID of Combo box to set data
; $sDefault: = The default number or letter that the combo box will display
; $iFlag: 0 = A To Z, 1= 0 To 9
Func _SetComboData($iCID, $sDefault, $iFlag = 0)
    Local $iStart = 65, $iFinsh = 90 ; From A ~ Z
    If $iFlag Then
        $iStart = 48 ; From 0
        $iFinsh = 57 ; To 9
    EndIf
    For $i = $iStart To $iFinsh
        GUICtrlSetData($iCID, Chr($i), $sDefault)
    Next
EndFunc

Other then that you could use GUIRegisterMsg(), WM_COMMAND and $EN_CHANGE to monitor when a user types in an input box and then handle filtering from there..

But to be truthful, it seems like more effort that way.

Cheers

Edited by smashly
Link to comment
Share on other sites

  • Moderators

tomson,

Welcome to the AutoIt forum. :(

Bem-vindo ao fórum do AutoIt. :)

Here is a little function to limit the input content to either a letter or a number:

#include <GUIConstantsEx.au3>

Global $sPrevText

$hGUI = GUICreate("Enter a letter", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45)
$hInput_Letter = GUICtrlCreateInput("", 10, 20, 30, 20)
GUICtrlSetLimit(-1, 1)
GUICtrlCreateLabel("Enter a letter", 50, 20, 100, 20)
$hInput_Number = GUICtrlCreateInput("", 10, 60, 30, 20)
GUICtrlSetLimit(-1, 1)
GUICtrlCreateLabel("Enter a Number", 50, 60, 100, 20)
$hButton = GUICtrlCreateButton("Exit", 200, 20, 80, 30)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hButton
            Exit
    EndSwitch

    _Input_Check($hInput_Letter, True) ; True means limit to letters
    _Input_Check($hInput_Number, False) ; False means limit to numbers


WEnd

Func _Input_Check($hInput, $fLetterFlag = True)

    ; Read input
    $sText = GUICtrlRead($hInput)
    If $fLetterFlag Then
        ; Upper case the input and reset the content
        $sText = StringUpper($sText)
        GUICtrlSetData($hInput, $sText)
    EndIf

    ; Check if there are any unwanted characters
    $sMsg = ""
    If $fLetterFlag Then
        ; And if so delete the non-letters
        If StringRegExp($sText, "[^A-Z]") Then GUICtrlSetData($hInput, StringRegExpReplace($sText, "[^A-Z]", ""))
    Else
        ; And if so delete the non-numbers
        If StringRegExp($sText, "[^0-9]") Then GUICtrlSetData($hInput, StringRegExpReplace($sText, "[^0-9]", ""))
    EndIf

EndFunc

I hope it does what you want - please ask if anything is unclear. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

THANKS A LOT FOR ALL!!!!!!!!!

I'm using an adapted code from smashly.....

Here it's:

$MainGRP = GUICtrlCreateGroup("", 16, 8, 481, 257)
$LinhaINPUT = GUICtrlCreateInput("3", 107, 30, 25, 21, BitOR($ES_CENTER, $ES_NUMBER))
$OrdemCOMBO = GUICtrlCreateCombo("", 235, 62, 33, 25, $CBS_DROPDOWNLIST)
CARACTER_COMBO($OrdemCOMBO, "B")
$HistoricoCOMBO = GUICtrlCreateCombo("", 172, 95, 33, 25, $CBS_DROPDOWNLIST)
CARACTER_COMBO($HistoricoCOMBO, "H")
$StatusOrdemCOMBO = GUICtrlCreateCombo("", 219, 127, 33, 25, $CBS_DROPDOWNLIST)
CARACTER_COMBO($StatusOrdemCOMBO, "F")
$StatusDetalhadoCOMBO = GUICtrlCreateCombo("", 220, 159, 33, 25, $CBS_DROPDOWNLIST)
CARACTER_COMBO($StatusDetalhadoCOMBO, "G")
$PastaTrabalhoINPUT = GUICtrlCreateInput("INSTRUMENTACAO", 203, 190, 206, 21)
$CaminhoPlanilhaINPUT = GUICtrlCreateInput($Local_Planilha, 24, 224, 385, 21)

Func CARACTER_COMBO($Control_ID, $ValorDefault)
; $Control_ID = Control ID do Combo Box que desejamos alterar o conteudo
; $ValorDefault = Valor padrao que terá o Combo Box
; $Marcacao_Do_Flag: 0 = A To Z, 1= 0 To 9 - nao utilizado, pois só usaremos letras

Local $ASCII_Inicial = 65 ; Definido a Variavel $ASCII_Inicial como Local (apenas para esta funcao) e com valor do Caracter 65 da tabela ASCII que representa o "A"
Local $ASCII_Final = 90   ; Definido a Variavel $ASCII_Inicial como Local (apenas para esta funcao) e com valor do Caracter 90 da tabela ASCII que representa o "Z"

For $i = $ASCII_Inicial To $ASCII_Final
    GUICtrlSetData($Control_ID, Chr($i), $ValorDefault)
Next

EndFunc

Thanks for ALL again.

Link to comment
Share on other sites

  • 2 years later...

I have written a simple function for this, but you must set character limit to 1

use it at While 1 or in a timer

Func letteronly($ControlID)
$checker = GUICtrlRead($ControlID)
If Not $checker = "" Then
  If Asc($checker) > 90 Or Asc($checker) < 65 Then
   GUICtrlSetData($ControlID,"")
  EndIf
EndIf
EndFunc

sorry for bad english

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...