tomson Posted April 15, 2010 Share Posted April 15, 2010 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 More sharing options...
smashly Posted April 15, 2010 Share Posted April 15, 2010 (edited) 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. expandcollapse popup#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 April 15, 2010 by smashly Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 15, 2010 Moderators Share Posted April 15, 2010 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: expandcollapse popup#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 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 Link to comment Share on other sites More sharing options...
tomson Posted April 15, 2010 Author Share Posted April 15, 2010 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 EndFuncThanks for ALL again. Link to comment Share on other sites More sharing options...
mfdemir Posted May 3, 2012 Share Posted May 3, 2012 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 Apples292 1 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