youtuber Posted June 18, 2023 Share Posted June 18, 2023 (edited) The regex pattern that the user entered in the ComboBox, here are sometimes separators in my regex patterns that I print to the ini file, Separator : | And an example of my regex pattern: (.com|\.net|\.org|\.info|\.biz|\.eu|\.fr|\.ch|\.kr|\.edu|\.us)(.*) When I read from the ini file and set data to the combobox, the regex pattern divides into parts, how can I prevent this? Thanks. expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> $aDirPro = @ScriptDir & "\IniFolder" If FileExists($aDirPro) = 0 Then DirCreate($aDirPro) $SectionName = "RegexPatterns" $Form1 = GUICreate("Form", 500, 200) $ComboSelectIniFile = GUICtrlCreateCombo("SelectIniFile", 160, 24, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) $ComboLoadPattern = GUICtrlCreateCombo("SelectPattern", 16, 56, 473, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) $ButtonSaveIni = GUICtrlCreateButton("SaveRegex", 16, 100, 475, 70) GUISetState(@SW_SHOW) _FUNC_INI_READ() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ComboSelectIniFile $Ini_FileNameReadCombo = $aDirPro & '\' & GUICtrlRead($ComboSelectIniFile) & '.ini' If GUICtrlRead($ComboSelectIniFile) <> 'SelectIniFile' Or GUICtrlRead($ComboSelectIniFile) > 0 Then GUICtrlSetData($ComboLoadPattern, "") GUICtrlSetData($ComboLoadPattern, IniRead($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', '')) EndIf Case $ButtonSaveIni $Ini_FileNameReadCombo = $aDirPro & '\' & GUICtrlRead($ComboSelectIniFile) & '.ini' If Not GUICtrlRead($ComboLoadPattern) = "" Then IniWrite($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', GUICtrlRead($ComboLoadPattern)) MsgBox(0, "Saved Ok.", "Regex pattern Saved Ok.", 3) GUICtrlSetData($ComboLoadPattern, "") GUICtrlSetData($ComboLoadPattern, IniRead($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', '')) Else MsgBox(48, "Incorrect operation!", "Cannot be empty - Regex patterns...", 5) GUICtrlSetState($ComboLoadPattern, $GUI_FOCUS) EndIf EndSwitch WEnd Func _FUNC_INI_READ() Local $INI_READ Local $VAR_READ $aIni_List = _FileListToArray($aDirPro, "*.ini", 1) $sIni_List = "" If Not @error Then For $i = 1 To $aIni_List[0] $sIni_List &= "|" & StringTrimRight($aIni_List[$i], 4) Next GUICtrlSetData($ComboSelectIniFile, $sIni_List) EndIf EndFunc ;==>_FUNC_INI_READ Spoiler Edited June 18, 2023 by youtuber Link to comment Share on other sites More sharing options...
Andreik Posted June 18, 2023 Share Posted June 18, 2023 (edited) You can change the default separator with AutoItSetOption('GUIDataSeparatorChar', '<separator>') Here is a full example: AutoItSetOption('GUIDataSeparatorChar', '^') $hMain = GUICreate("Example", 400, 200) $cCombo = GUICtrlCreateCombo('', 10, 10, 380, 20) GUICtrlSetData($cCombo, '(.com|\.net|\.org|\.info|\.biz|\.eu|\.fr|\.ch|\.kr|\.edu|\.us)(.*)') GUISetState(@SW_SHOW, $hMain) Do Sleep(10) Until GUIGetMsg() = -3 You can even have a specialized function to set data in combo with a certain separator and then restore the default separator: $hMain = GUICreate("Example", 400, 200) $cCombo = GUICtrlCreateCombo('', 10, 10, 380, 20) SetCombo($cCombo, '(.com|\.net|\.org|\.info|\.biz|\.eu|\.fr|\.ch|\.kr|\.edu|\.us)(.*)', '^') GUICtrlSetData($cCombo, 'Item 1|Item 2') GUISetState(@SW_SHOW, $hMain) Do Sleep(10) Until GUIGetMsg() = -3 Func SetCombo($cCombo, $sData, $sSeparator) Local $sPrevSeparator = AutoItSetOption('GUIDataSeparatorChar', $sSeparator) GUICtrlSetData($cCombo, $sData) AutoItSetOption('GUIDataSeparatorChar', $sPrevSeparator) EndFunc Edited June 18, 2023 by Andreik youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted June 18, 2023 Author Share Posted June 18, 2023 Thank you, but it must be a character not in regex pattern. Do you have a different solution for this? For example, if the user enters an regex pattern like this... ^.*\\|\..*$ Link to comment Share on other sites More sharing options...
Andreik Posted June 18, 2023 Share Posted June 18, 2023 (edited) It was just an example. You can pick whatever you want as separator. $hMain = GUICreate("Example", 400, 200) $cCombo = GUICtrlCreateCombo('', 10, 10, 380, 20) SetCombo($cCombo, '(.com|\.net|\.org|\.info|\.biz|\.eu|\.fr|\.ch|\.kr|\.edu|\.us)(.*)', Chr(5)) GUICtrlSetData($cCombo, 'Item 1|Item 2') GUISetState(@SW_SHOW, $hMain) Do Sleep(10) Until GUIGetMsg() = -3 Func SetCombo($cCombo, $sData, $sSeparator) Local $sPrevSeparator = AutoItSetOption('GUIDataSeparatorChar', $sSeparator) GUICtrlSetData($cCombo, $sData) AutoItSetOption('GUIDataSeparatorChar', $sPrevSeparator) EndFunc Edited June 18, 2023 by Andreik youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted June 18, 2023 Author Share Posted June 18, 2023 same problem persists when i try by reading from ini file expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> $aDirPro = @ScriptDir & "\IniFolder" If FileExists($aDirPro) = 0 Then DirCreate($aDirPro) $SectionName = "RegexPatterns" $Form1 = GUICreate("Form", 500, 200) $ComboSelectIniFile = GUICtrlCreateCombo("SelectIniFile", 160, 24, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) $ComboLoadPattern = GUICtrlCreateCombo("SelectPattern", 16, 56, 473, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) SetCombo($ComboLoadPattern, '(.com|\.net|\.org|\.info|\.biz|\.eu|\.fr|\.ch|\.kr|\.edu|\.us)(.*)', Chr(5)) GUICtrlSetData($ComboLoadPattern, 'Item 1|Item 2') $ButtonSaveIni = GUICtrlCreateButton("SaveRegex", 16, 100, 475, 70) GUISetState(@SW_SHOW) _FUNC_INI_READ() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ComboSelectIniFile $Ini_FileNameReadCombo = $aDirPro & '\' & GUICtrlRead($ComboSelectIniFile) & '.ini' If GUICtrlRead($ComboSelectIniFile) <> 'SelectIniFile' Or GUICtrlRead($ComboSelectIniFile) > 0 Then GUICtrlSetData($ComboLoadPattern, "") GUICtrlSetData($ComboLoadPattern, IniRead($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', '')) EndIf Case $ButtonSaveIni $Ini_FileNameReadCombo = $aDirPro & '\' & GUICtrlRead($ComboSelectIniFile) & '.ini' If Not GUICtrlRead($ComboLoadPattern) = "" Then IniWrite($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', GUICtrlRead($ComboLoadPattern)) MsgBox(0, "Saved Ok.", "Regex pattern Saved Ok.", 3) GUICtrlSetData($ComboLoadPattern, "") GUICtrlSetData($ComboLoadPattern, IniRead($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', '')) Else MsgBox(48, "Incorrect operation!", "Cannot be empty - Regex patterns...", 5) GUICtrlSetState($ComboLoadPattern, $GUI_FOCUS) EndIf EndSwitch WEnd Func SetCombo($cComboX, $sData, $sSeparator) Local $sPrevSeparator = AutoItSetOption('GUIDataSeparatorChar', $sSeparator) GUICtrlSetData($ComboLoadPattern, $sData) AutoItSetOption('GUIDataSeparatorChar', $sPrevSeparator) EndFunc Func _FUNC_INI_READ() Local $INI_READ Local $VAR_READ $aIni_List = _FileListToArray($aDirPro, "*.ini", 1) $sIni_List = "" If Not @error Then For $i = 1 To $aIni_List[0] $sIni_List &= "|" & StringTrimRight($aIni_List[$i], 4) Next GUICtrlSetData($ComboSelectIniFile, $sIni_List) EndIf EndFunc ;==>_FUNC_INI_READ Spoiler Link to comment Share on other sites More sharing options...
Andreik Posted June 18, 2023 Share Posted June 18, 2023 Post the ini file. youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted June 18, 2023 Author Share Posted June 18, 2023 (edited) [RegexPatterns] REGEXPATTERN=(.com|\.net|\.org|\.info|\.biz|\.eu|\.fr|\.ch|\.kr|\.edu|\.us)(.*) Test.ini Edited June 18, 2023 by youtuber Link to comment Share on other sites More sharing options...
Andreik Posted June 18, 2023 Share Posted June 18, 2023 (edited) Case $ComboSelectIniFile $Ini_FileNameReadCombo = $aDirPro & '\' & GUICtrlRead($ComboSelectIniFile) & '.ini' If GUICtrlRead($ComboSelectIniFile) <> 'SelectIniFile' Or GUICtrlRead($ComboSelectIniFile) > 0 Then GUICtrlSetData($ComboLoadPattern, "") GUICtrlSetData($ComboLoadPattern, IniRead($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', '')) ; ???? EndIf Case $ButtonSaveIni $Ini_FileNameReadCombo = $aDirPro & '\' & GUICtrlRead($ComboSelectIniFile) & '.ini' If Not GUICtrlRead($ComboLoadPattern) = "" Then IniWrite($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', GUICtrlRead($ComboLoadPattern)) MsgBox(0, "Saved Ok.", "Regex pattern Saved Ok.", 3) GUICtrlSetData($ComboLoadPattern, "") GUICtrlSetData($ComboLoadPattern, IniRead($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', '')) ; ???? How do you expect to work if you don't use the function that change default separator? SetCombo($ComboLoadPattern, IniRead($Ini_FileNameReadCombo, $SectionName, 'REGEXPATTERN', ''), Chr(5)) Edited June 18, 2023 by Andreik youtuber 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