Brenmank Posted January 24, 2016 Share Posted January 24, 2016 I am new to Autoit, and I have created a GUI form that users will enter a project number and Project name into a input box. The program will then create a directory on our file servers based on the information in the forms. I want to create an input mask I can control the information entered. Here is how I would like each box's data to look. Project # 12-1234-00. - I want the - to always appear in the third and 8 spot. The user would only have to typew 12123400, and the information would automatically format itself., Project Name - I just need an input to replace any spaces with an underscore. Any help that someone could provide would be great. Thanks... Link to comment Share on other sites More sharing options...
AutoBert Posted January 24, 2016 Share Posted January 24, 2016 38 minutes ago, Brenmank said: Project Name - I just need an input to replace any spaces with an underscore. ...Any help that someone could provide would be great. StringReplace is the magic func for this: StringReplace Replaces substrings in a string. StringReplace ( "string", "searchstring/start", "replacestring" [, occurrence = 0 [, casesense = 0]] ) Have a look in the helpfile and it's example to understand. Link to comment Share on other sites More sharing options...
UEZ Posted January 24, 2016 Share Posted January 24, 2016 (edited) Here the input section: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test GUI", 581, 43) $iLable = GUICtrlCreateLabel("Project #", 6, 8, 72, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $iInput = GUICtrlCreateInput("", 96, 8, 385, 21) $iButton = GUICtrlCreateButton("Button", 496, 8, 75, 25) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIRegisterMsg($WM_COMMAND, "") GUIDelete() Exit EndSwitch WEnd Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $iInput Then Local $s = StringRegExpReplace(GUICtrlRead($iInput), "[^0-9]", "") GUICtrlSetData($iInput, $s) Switch StringLen($s) Case 3 to 6 GUICtrlSetData($iInput, StringLeft($s, 2) & "-" & StringMid($s, 3)) Case 7 To 10 GUICtrlSetData($iInput, StringLeft($s, 2) & "-" & StringMid($s, 3, 4) & "-" & StringMid($s, 7, 2)) EndSwitch EndIf Return "GUI_RUNDEFMSG" EndFunc The 2nd part is very easy by following what AutoBert has said. Edited January 24, 2016 by UEZ Fixed issue when non digits were entered. spudw2k 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Brenmank Posted January 24, 2016 Author Share Posted January 24, 2016 Thanks for all the help. I will give it a try... Link to comment Share on other sites More sharing options...
mikell Posted January 25, 2016 Share Posted January 25, 2016 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test GUI", 530, 70) GUICtrlCreateLabel("Project #", 6, 8, 110, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $iInput1 = GUICtrlCreateInput("", 120, 8, 385, 21) GUICtrlSetLimit(-1, 10) GUICtrlCreateLabel("Project name", 6, 35, 110, 25) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $iInput2 = GUICtrlCreateInput("", 120, 35, 385, 21) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIRegisterMsg($WM_COMMAND, "") GUIDelete() Exit EndSwitch WEnd Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Switch BitAND($wParam, 0x0000FFFF) Case $iInput1 Local $s = StringRegExpReplace(GUICtrlRead($iInput1), '\D', "") GUICtrlSetData($iInput1, StringRegExpReplace($s, '(^\d{2})|(\d{4})\K', "$1-") ) Case $iInput2 GUICtrlSetData($iInput2, StringRegExpReplace(GUICtrlRead($iInput2), '[\h_]+', "_")) EndSwitch Return "GUI_RUNDEFMSG" EndFunc spudw2k 1 Link to comment Share on other sites More sharing options...
Tormund Posted July 6, 2016 Share Posted July 6, 2016 Hello Guys, I´ve a very similar situation here. There is one inputbox in my GUI which I should receive a Product-ID and I would like to use this very good solution provided by @mikell to avoid problems of mistyping. My project ID is like this example: 1234567-89.2016.8.19.0001 The biggest problem with my Product-ID is related to the existence of two different types of separators such as "-" and " . " and because of this I´ve no idea to solve this using Regex.... maybe the best approach is StringReplace but once that I my ID is so big, StringReplace is killing me. So I was wondering if someone here could help me to achieve this goal... Cheers Link to comment Share on other sites More sharing options...
Tormund Posted July 6, 2016 Share Posted July 6, 2016 2 hours ago, Tormund said: Hello Guys, I´ve a very similar situation here. There is one inputbox in my GUI which I should receive a Product-ID and I would like to use this very good solution provided by @mikell to avoid problems of mistyping. My project ID is like this example: 1234567-89.2016.8.19.0001 The biggest problem with my Product-ID is related to the existence of two different types of separators such as "-" and " . " and because of this I´ve no idea to solve this using Regex.... maybe the best approach is StringReplace but once that I my ID is so big, StringReplace is killing me. So I was wondering if someone here could help me to achieve this goal... Cheers Thank you guys, I just found a way to achieve what I was looking for. I´ll post the code here for future reference. By the way, I just modified the code for my needs. The original post came from this thread (http://forum.autoitbrasil.com) Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iCode = BitShift($wParam, 16) Local $iIDFrom = _WinAPI_LoWord($wParam) Switch $iIDFrom Case $tbMyInputNumber Switch $iCode Case $EN_UPDATE Local $sWMCOMMAND_MyInputNumberRead = GUICtrlRead($tbMyInputNumber) Local $sWMCOMMAND_MyInputNumberLastChar = StringRight($sWMCOMMAND_MyInputNumberRead, 1) Local $aWMCOMMAND_MyInputNumberDotSplit = StringSplit($sWMCOMMAND_MyInputNumberRead, "/") If StringLen($sWMCOMMAND_MyInputNumberRead) = 7 Then GUICtrlSetData($tbMyInputNumber, $sWMCOMMAND_MyInputNumberRead & "-") ElseIf StringLen($sWMCOMMAND_MyInputNumberRead) = 10 Then GUICtrlSetData($tbMyInputNumber, $sWMCOMMAND_MyInputNumberRead & ".") ElseIf StringLen($sWMCOMMAND_MyInputNumberRead) = 15 Then GUICtrlSetData($tbMyInputNumber, $sWMCOMMAND_MyInputNumberRead & ".") ElseIf StringLen($sWMCOMMAND_MyInputNumberRead) = 17 Then GUICtrlSetData($tbMyInputNumber, $sWMCOMMAND_MyInputNumberRead & ".") ElseIf StringLen($sWMCOMMAND_MyInputNumberRead) = 20 Then GUICtrlSetData($tbMyInputNumber, $sWMCOMMAND_MyInputNumberRead & ".") ElseIf StringLen($sWMCOMMAND_MyInputNumberRead) = 25 Then GUICtrlSetData($tbMyInputNumber, $sWMCOMMAND_MyInputNumberRead) EndIf Case Else EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND 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