Jump to content

GUICtrlCreateInput mask


rlatrasse
 Share

Recommended Posts

Hello

I want to create a mask on the control GUICtrlCreateInput to force "." between two digits.

The final format would be 00.00.00.00.00

Best regards

I don't know how to do that in AutoIt though in other languages it can be quite easy. In case no gives a clever method you could do something like this, but obviously add som more inputs.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 413, 237, 339, 251)
$Input1 = GUICtrlCreateInput("", 107, 136, 21, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER,$WS_BORDER), 0)
GUICtrlSetLimit(-1,2)
$Label2 = GUICtrlCreateLabel(".", 128, 136, 8, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

rlatrasse,

Just happened to have this handy!

#include <GUIConstantsEx.au3>

Global $input_limit = 2

$gui = GUICreate("InputBox autofocus demo", 310, 100)
$in1 = GUICtrlCreateInput("", 20, 20, 30, 20)
GUICtrlSetLimit(-1, $input_limit)
$in2 = GUICtrlCreateInput("", 80, 20, 30, 20)
GUICtrlSetLimit(-1, $input_limit)
$in3 = GUICtrlCreateInput("", 140, 20, 30, 20)
GUICtrlSetLimit(-1, $input_limit)
$in4 = GUICtrlCreateInput("", 200, 20, 30, 20)
GUICtrlSetLimit(-1, $input_limit)
$in5 = GUICtrlCreateInput("", 260, 20, 30, 20)
GUICtrlSetLimit(-1, $input_limit)
$btn = GUICtrlCreateButton("OK", 135, 60, 50, 25)

GUIRegisterMsg(0x0111, "On_WM_COMMAND")
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn
            $str = GUICtrlRead($in1) & "." & GUICtrlRead($in2) & "." & GUICtrlRead($in3) & "." & GUICtrlRead($in4) & "." & GUICtrlRead($in5)
            MsgBox(0, "You have entered", $str)
    EndSwitch
WEnd

Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAnd($wParam, 0x0000FFFF)
    Switch $nNotifyCode
        Case 0x400;$EN_UPDATE
            If StringLen(GUICtrlRead($nID)) = $input_limit Then GUICtrlSetState($nID+1, $GUI_FOCUS)
    EndSwitch
EndFunc

Hope it is helpful.

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

Hello

I want to create a mask on the control GUICtrlCreateInput to force "." between two digits.

The final format would be 00.00.00.00.00

Best regards

Here's a crappy way of doing it:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)

GUICreate("",262,109)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Close")

$Input = GUICtrlCreateInput("....", 24, 32, 217, 21,$ES_CENTER)
GUIRegisterMsg(0x0111,"_ForceFormat")

GUISetState(@SW_SHOW)
While 1
    Sleep(100)
WEnd

Func _ForceFormat($hWnd,$Msg)
$string = StringReplace(GUICtrlRead($Input),".","")
$string =   StringMid($string,1,2) & "." & _
            StringMid($string,3,2) & "." & _
            StringMid($string,5,2) & "." & _
            StringMid($string,7,2) & "." & _
            StringMid($string,9,2)
GUICtrlSetData($Input,$string)
EndFunc

Func _Close()
    Exit
EndFunc

A bit of Regular Expression may make it a bit better.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Global $INPUT
$GUI = GUICreate("Example",200,200)
$INPUT = GUICtrlCreateInput("",50,50,80,20)
GUIRegisterMsg(0x0111,"Mask")
GUISetState()

While 1
    If GUIGetMsg() = -3 Then Exit
    Sleep(20)
WEnd

Func Mask()
If StringLen(GUICtrlRead($INPUT)) < 14 Then
Local $DATA = ""
$TEXT = StringReplace(GUICtrlRead($INPUT),".","")
Local $LEN = StringLen($TEXT)
If $LEN > 10 Then $TEXT = StringLeft($TEXT,10)
For $INDEX = 1 To $LEN Step 2
$DATA &= StringMid($TEXT,$INDEX,2) & "."
Next
If Mod($LEN,2) = 1 Then $DATA = StringTrimRight($DATA,1)
GUICtrlSetData($INPUT,$DATA)
ElseIf StringLen(GUICtrlRead($INPUT)) > 14 Then
GUICtrlSetData($INPUT,StringLeft(GUICtrlRead($INPUT),14))
EndIf
EndFunc

When the words fail... music speaks.

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