caramen Posted October 3, 2020 Share Posted October 3, 2020 Hello guys I'm trying to do something new : The goal : Highlight text I have a string regex already working to find information in my Body Field. The purpose is to Highlight each occurrence of my regex in my body field. Exactly like regex101 : Everything is ready, but I don't know what to use. No chance with the research in help file or our best friend google. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
water Posted October 3, 2020 Share Posted October 3, 2020 IIRC this is only possible with a rich text control. But I think it can become quite complex My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Subz Posted October 3, 2020 Share Posted October 3, 2020 It would have to be rich text wouldn't it to get color? Or use embedded html window? See water bet me to it. Link to comment Share on other sites More sharing options...
caramen Posted October 3, 2020 Author Share Posted October 3, 2020 Do you guys have some examples of rich controls ? I never used them. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Subz Posted October 3, 2020 Share Posted October 3, 2020 Sorry haven't used them in years, there are few examples on the forum for example: caramen 1 Link to comment Share on other sites More sharing options...
caramen Posted October 3, 2020 Author Share Posted October 3, 2020 (edited) Thanks mate, very cool example. Well it wasn't so hard 😛 expandcollapse popup#include <Color.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Global $g_hRichEdit , $StringStart , $StringEnd HotKeySet("{Escape}", "_Exit") ;Shift-Alt-E to Exit the script Global $StringATester002 = "\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d|\d\d\d\d[-.\s]\d\d\d[-.\s]\d\d\d" ;Un numéro de tél FR (A revoir) Example() Func Example() Local $hGui, $idBtnNext, $iStep = 0 $hGui = GUICreate(StringTrimRight(@ScriptName, StringLen(".exe")), 420, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create( $hGui, 'Bonjour mon numéro de téléphone est le 06.12.34.56.78', _ 10, 10, 400, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($g_hRichEdit) ; needed unless script crashes GUIDelete() Exit Case $idBtnNext _StringEarlyLateCount () _GUICtrlRichEdit_SetSel($g_hRichEdit, $StringStart-1 , $StringStart+$StringEnd ) _GUICtrlRichEdit_SetCharBkColor($g_hRichEdit, Dec('00FF00')) ; Red _GUICtrlRichEdit_Deselect($g_hRichEdit) EndSwitch WEnd EndFunc ;==>Example Func _StringEarlyLateCount () $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) Global $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[0] , 0 , 1 ) ConsoleWrite ( $StringStart& @CRLF ) Global $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ( $StringEnd & @CRLF ) EndFunc Func _Exit() ;On quitte le script Exit EndFunc ;==>_Exit Edited October 3, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
caramen Posted October 3, 2020 Author Share Posted October 3, 2020 (edited) I'm getting stuck with this logic I can't check for occurrence.... expandcollapse popup#include <Color.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <Array.au3> Global $g_hRichEdit , $StringStart , $StringEnd , $A , $B Global $Occurence = 0 Global $i = 0 Global $f = 0 HotKeySet("{Escape}", "_Exit") ;Shift-Alt-E to Exit the script Global $StringATester002 = "\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d|\d\d\d\d[-.\s]\d\d\d[-.\s]\d\d\d" ;Un numéro de tél FR (A revoir) $StringATester = "" Example() Func Example() Local $hGui, $idBtnNext, $iStep = 0 $hGui = GUICreate(StringTrimRight(@ScriptName, StringLen(".exe")), 420, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create( $hGui, 'Bonjour mon numéro de téléphone est le 06.12.34.56.78 ou 07 78 98 95 95', _ 10, 10, 400, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($g_hRichEdit) ; needed unless script crashes GUIDelete() Exit Case $idBtnNext $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) $Stringcalcule = Ubound ($StringATester) $Stringcalcule -= 1 $Occurence = $Stringcalcule ; 1 For $i=0 To $Stringcalcule Step 1 _StringEarlyLateCount () $Occurence += 1 _GUICtrlRichEdit_SetSel($g_hRichEdit, $StringStart-1 , $StringStart+$StringEnd ) _GUICtrlRichEdit_SetCharBkColor($g_hRichEdit, Dec('00FF00')) ; Red _GUICtrlRichEdit_Deselect($g_hRichEdit) Next EndSwitch WEnd EndFunc ;==>Example Func _StringEarlyLateCount () ConsoleWrite ( "$Occurence="&$Occurence& @CRLF ) ConsoleWrite ( "î="&$i& @CRLF ) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _ArrayDisplay ( $StringATester ) Global $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$i] , 0 , $Occurence ) ; -> 2 ;$StringATester[0] -> ;$StringATester[1] ConsoleWrite ( "$StringStart"&$StringStart& @CRLF ) Global $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ("$StringEnd"& $StringEnd & @CRLF ) EndFunc Func _Exit() ;On quitte le script Exit EndFunc ;==>_Exit Edit : Haha... of course, it does not work this isn't an occurrence xD 06.12.34.56.78 ou 07 78 98 95 95 Working with real occurence lol... 06.12.34.56.78 ou 06.12.34.56.78 Edited October 3, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
caramen Posted October 3, 2020 Author Share Posted October 3, 2020 (edited) I'm almost on the total highlight any case/. But nop x) It's now complicated yeah expandcollapse popup#include <Color.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <Array.au3> Global $g_hRichEdit , $StringStart , $StringEnd , $A , $B Global $i = 0 Global $f = 0 HotKeySet("{Escape}", "_Exit") ;Shift-Alt-E to Exit the script Global $StringATester002 = "\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d|\d\d\d\d[-.\s]\d\d\d[-.\s]\d\d\d" ;Un numéro de tél FR (A revoir) $StringATester = "" Example() Func Example() Local $hGui, $idBtnNext, $iStep = 0 $hGui = GUICreate(StringTrimRight(@ScriptName, StringLen(".exe")), 420, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create( $hGui, 'Bonjour mon numéro de téléphone est le 06.12.34.56.78 06.12.34.56.78 ou 07.12.34.56.78 08.12.34.56.78 09.12.34.56.78', _ 10, 10, 400, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($g_hRichEdit) ; needed unless script crashes GUIDelete() Exit Case $idBtnNext $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _FindAllInArray () $Stringcalcule = Ubound ($StringATester) $Stringcalcule -= 1 For $i=0 To $Stringcalcule Step 1 _StringEarlyLateCount () _GUICtrlRichEdit_SetSel($g_hRichEdit, $StringStart-1 , $StringStart+$StringEnd ) _GUICtrlRichEdit_SetCharBkColor($g_hRichEdit, Dec('00FF00')) ; Red _GUICtrlRichEdit_Deselect($g_hRichEdit) Next EndSwitch WEnd EndFunc ;==>Example Func _StringEarlyLateCount () ConsoleWrite ( "A="&$A& @CRLF ) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _ArrayDisplay ( $StringATester ) Global $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$A] , 0 , 1 ) ; -> 2 $A += 1 ;$StringATester[0] -> ;$StringATester[1] ConsoleWrite ( "$StringStart"&$StringStart& @CRLF ) Global $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ("$StringEnd"& $StringEnd & @CRLF ) EndFunc Func _FindAllInArray () Local $iaRowA = 0 Local $iaRowB = 0 Local $aiResult _ArrayDisplay ( $StringATester ) Do $aiResult = _ArrayFindAll($StringATester, $StringATester[$iaRowA]) _ArrayDisplay($aiResult, "Found") $aiResult = Ubound ($aiResult) $iaRowA += $aiResult ConsoleWrite ("Calcule = $iaRowA "&$iaRowA&" + $aiResult "&$aiResult&" "&@CRLF) MsgBox (0,0,$aiResult) Until $iaRowA > UBound ($StringATester) - 1 EndFunc Func _Exit() ;On quitte le script Exit EndFunc ;==>_Exit I was on the way to use _ArrayFindAll To Ubound everything And do comparison etc... I don't have a way to get all numbers highlighted, yet I'm on it Grrrrrr ! Edited October 3, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Musashi Posted October 3, 2020 Share Posted October 3, 2020 2 minutes ago, caramen said: It's now complicated yeah Just a small hint : I would avoid Global declarations within functions . Func _StringEarlyLateCount () [...] Global $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$A] , 0 , 1 ) ; -> 2 TheXman 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
caramen Posted October 3, 2020 Author Share Posted October 3, 2020 (edited) Oh, Yeah It's because I did a lot of CTRL + Z If you notice I declared them at top but Control Z rewrote them. It's to make copy of different logic. May you can advise me on my issue ? Edited October 3, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Musashi Posted October 3, 2020 Share Posted October 3, 2020 (edited) 21 minutes ago, caramen said: May you can advise me on my issue ? Instead : Func _StringEarlyLateCount () ConsoleWrite ( "A="&$A& @CRLF ) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _ArrayDisplay ( $StringATester ) Global $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$A] , 0 , 1 ) ; -> 2 $A += 1 ;$StringATester[0] -> ;$StringATester[1] ConsoleWrite ( "$StringStart"&$StringStart& @CRLF ) Global $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ("$StringEnd"& $StringEnd & @CRLF ) EndFunc Use : Func _StringEarlyLateCount () ConsoleWrite ( "A="&$A& @CRLF ) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _ArrayDisplay ( $StringATester ) $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$A] , 0 , 1 ) ; -> 2 $A += 1 ;$StringATester[0] -> ;$StringATester[1] ConsoleWrite ( "$StringStart"&$StringStart& @CRLF ) $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ("$StringEnd"& $StringEnd & @CRLF ) EndFunc $StringStart and $StringEnd are already declared in the global scope. It is, as I already wrote, a formal issue . Edited October 3, 2020 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
caramen Posted October 3, 2020 Author Share Posted October 3, 2020 (edited) 4 minutes ago, Musashi said: Instead : Func _StringEarlyLateCount () ConsoleWrite ( "A="&$A& @CRLF ) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _ArrayDisplay ( $StringATester ) Global $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$A] , 0 , 1 ) ; -> 2 $A += 1 ;$StringATester[0] -> ;$StringATester[1] ConsoleWrite ( "$StringStart"&$StringStart& @CRLF ) Global $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ("$StringEnd"& $StringEnd & @CRLF ) EndFunc Use : Func _StringEarlyLateCount () ConsoleWrite ( "A="&$A& @CRLF ) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _ArrayDisplay ( $StringATester ) $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$A] , 0 , 1 ) ; -> 2 $A += 1 ;$StringATester[0] -> ;$StringATester[1] ConsoleWrite ( "$StringStart"&$StringStart& @CRLF ) $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ("$StringEnd"& $StringEnd & @CRLF ) EndFunc $StringStart and $StringEnd are already declared in the global scope. It is, as I already wrote, only a formal issue . Wrong Ops 06.12.34.56.78 Occurrence Two Is not highlighted Same as before. Edited October 3, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Musashi Posted October 3, 2020 Share Posted October 3, 2020 5 minutes ago, caramen said: Same as before. I just wanted to point out the declaration. In the present case it is not the reason why the second occurrence is not displayed. Unfortunately I am suffering under a hangover from last night. Therefore I lack the concentration to analyze your script in general . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted October 3, 2020 Share Posted October 3, 2020 The problem seems to be, that the first and second numbers are identical (06.12.34.56.78). Therefore, the second number is not colored because the position values of the first number are used. Calcule = $iaRowA 2 + $aiResult 2 Calcule = $iaRowA 3 + $aiResult 1 Calcule = $iaRowA 4 + $aiResult 1 Calcule = $iaRowA 5 + $aiResult 1 A= $StringStart40 $StringEnd14 A=1 $StringStart40 $StringEnd14 A=2 $StringStart73 $StringEnd14 A=3 $StringStart88 $StringEnd14 A=4 $StringStart103 $StringEnd14 If all numbers are different, it looks like this (and works): Calcule = $iaRowA 1 + $aiResult 1 Calcule = $iaRowA 2 + $aiResult 1 Calcule = $iaRowA 3 + $aiResult 1 Calcule = $iaRowA 4 + $aiResult 1 Calcule = $iaRowA 5 + $aiResult 1 A= $StringStart40 $StringEnd14 A=1 $StringStart55 $StringEnd14 A=2 $StringStart73 $StringEnd14 A=3 $StringStart88 $StringEnd14 A=4 $StringStart103 $StringEnd14 That is alas all I can say at the moment . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
caramen Posted October 3, 2020 Author Share Posted October 3, 2020 (edited) I can say more x) I think the solution is to implement parameter 4 of : StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$A] , 0 , 1 ) 1 to the number of occurrence depending on the Ubund of an eventual array process. I'm still searching. You could look my precedents post you'll see an example working with occurrences. But this one reproducer doesn't work with occurrence but with all match. Which is not the case of first example x) Edited October 3, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
caramen Posted October 4, 2020 Author Share Posted October 4, 2020 (edited) Next level ! if someone know how to find multiple occurrence. expandcollapse popup#include <Color.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <Array.au3> Global $g_hRichEdit , $StringStart , $StringEnd , $A , $B Global $Occurence = 0 Global $i = 0 Global $f = 0 HotKeySet("{Escape}", "_Exit") ;Shift-Alt-E to Exit the script Global $StringATester002 = "\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d|\d\d\d\d[-.\s]\d\d\d[-.\s]\d\d\d" ;Un numéro de tél FR (A revoir) $StringATester = "" Example() Func Example() Local $hGui, $idBtnNext, $iStep = 0 $hGui = GUICreate(StringTrimRight(@ScriptName, StringLen(".exe")), 420, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create( $hGui, 'Bonjour mon numéro de téléphone est le 06.12.34.56.78 JE repete le 06.12.34.56.78 ou 07.12.34.56.78 08.12.34.56.78 Je repete le 08.12.34.56.78 09.12.34.56.78', _ 10, 10, 400, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($g_hRichEdit) ; needed unless script crashes GUIDelete() Exit Case $idBtnNext $A = 0 $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _FindAllInArray () $Stringcalcule = Ubound ($StringATester) $Stringcalcule -= 1 For $i=0 To $Stringcalcule Step 1 _StringEarlyLateCount () _GUICtrlRichEdit_SetSel($g_hRichEdit, $StringStart-1 , $StringStart+$StringEnd ) _GUICtrlRichEdit_SetCharBkColor($g_hRichEdit, Dec('00FF00')) ; Red _GUICtrlRichEdit_Deselect($g_hRichEdit) Next ConsoleWrite ("============Boucle 2==========="& @CRLF) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) ;~ ConsoleWrite ( "" ) $Stringcalcule = Ubound ($StringATester) ConsoleWrite ( "Ubound = "&$Stringcalcule & @CRLF) $Stringcalcule -= 0 ConsoleWrite ( "Ubound-1 = "&$Stringcalcule & @CRLF) $Occurence = $Stringcalcule ; 1 For $i=0 To $Stringcalcule Step 1 _StringEarlyLateCount2 () $Occurence -= 1 _GUICtrlRichEdit_SetSel($g_hRichEdit, $StringStart-1 , $StringStart+$StringEnd ) _GUICtrlRichEdit_SetCharBkColor($g_hRichEdit, Dec('00FF00')) ; Red _GUICtrlRichEdit_Deselect($g_hRichEdit) Next EndSwitch WEnd EndFunc ;==>Example Func _StringEarlyLateCount () ConsoleWrite ( "A="&$A& @CRLF ) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) ;~ _ArrayDisplay ( $StringATester ) $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$A] , 0 , 1 ) ; -> 2 $A += 1 ;$StringATester[0] -> ;$StringATester[1] ConsoleWrite ( "$StringStart"&$StringStart& @CRLF ) $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ("$StringEnd"& $StringEnd & @CRLF ) EndFunc Func _FindAllInArray () Local $iaRowA = 0 Local $iaRowB = 0 Local $aiResult _ArrayDisplay ( $StringATester ) Do $aiResult = _ArrayFindAll($StringATester, $StringATester[$iaRowA]) ;~ _ArrayDisplay($aiResult, "Found") $aiResult = Ubound ($aiResult) $iaRowA += $aiResult ConsoleWrite ("Calcule = $iaRowA "&$iaRowA&" + $aiResult "&$aiResult&" "&@CRLF) ;~ MsgBox (0,0,$aiResult) Until $iaRowA > UBound ($StringATester) - 1 EndFunc Func _StringEarlyLateCount2 () ConsoleWrite ( "$Occurence="&$Occurence& @CRLF ) ConsoleWrite ( "î="&$i& @CRLF ) $StringATester = StringRegExp( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester002 , 3 ) _ArrayDisplay ( $StringATester ) $StringStart = StringInStr ( _GUICtrlRichEdit_GetText ( $g_hRichEdit ) , $StringATester[$i] , 0 , $Occurence ) ; -> 2 ;$StringATester[0] -> ;$StringATester[1] ConsoleWrite ( "$StringStart"&$StringStart& @CRLF ) $StringEnd = StringLen ( $StringATester[0] ) ConsoleWrite ("$StringEnd"& $StringEnd & @CRLF ) EndFunc Func _Exit() ;On quitte le script Exit EndFunc ;==>_Exit Edited October 4, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
caramen Posted October 4, 2020 Author Share Posted October 4, 2020 (edited) I got a more more more simple solution. From the example that working only with different result. If you notice it will pass two time on the same result and the occurrence does not change so visually there is no effect but this is not true. It is highlighting the same result two time. So a simple way to solve this would be to check at each highlighting if "SOMETHING" is the same as before (can be string or even console write value...) Then increment occurrence. But Else occurrence = 1 From the function I read We could check if the text is already highlighted too I'm gonna check this after I do pause. Edited October 4, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Musashi Posted October 4, 2020 Share Posted October 4, 2020 Here is an alternative approach : I create the global array $g_aRichEditFields , which already contains the start and end positions. expandcollapse popup#include <Color.au3> #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <Array.au3> HotKeySet("{Escape}", "_Exit") ; Shift-Alt-E to Exit the script Global $g_hRichEdit , $g_aRichEditFields[0][3], $g_sSearchPattern, $g_iIndex = 1, $g_bMatchesFound = False $g_sSearchPattern = "\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d[-.\s]\d\d|\d\d\d\d[-.\s]\d\d\d[-.\s]\d\d\d" ; Un numéro de tél FR (A revoir) Example() Func Example() Local $hGui, $idBtnNext, $iStep = 0 $hGui = GUICreate(StringTrimRight(@ScriptName, StringLen(".exe")), 420, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create( $hGui, 'Bonjour mon numéro de téléphone est le 06.12.34.56.78 06.12.34.56.78 ou 07.12.34.56.78 08.12.34.56.78 06.12.34.56.78 09.12.34.56.78', _ 10, 10, 400, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30) GUISetState(@SW_SHOW) If _GenerateRichEditFields() Then $g_bMatchesFound = True While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($g_hRichEdit) ; needed unless script crashes GUIDelete() Exit Case $idBtnNext If $g_bMatchesFound Then If $g_iIndex <= $g_aRichEditFields[0][0] Then _GUICtrlRichEdit_SetSel($g_hRichEdit, $g_aRichEditFields[$g_iIndex][1] , $g_aRichEditFields[$g_iIndex][2]) _GUICtrlRichEdit_SetCharBkColor($g_hRichEdit, Dec('00FF00')) ; Red _GUICtrlRichEdit_Deselect($g_hRichEdit) $g_iIndex += 1 Else $g_iIndex = 1 EndIf EndIf EndSwitch WEnd EndFunc ;==>Example Func _GenerateRichEditFields() Local $aMatches, $iStringStart, $iStringEnd, $iOffset = 1 $aMatches = StringRegExp(_GUICtrlRichEdit_GetText($g_hRichEdit), $g_sSearchPattern , 3) If @error Then Return 0 ReDim $g_aRichEditFields[UBound($aMatches) + 1][3] $g_aRichEditFields[0][0] = UBound($aMatches) For $i = 0 To UBound($aMatches) - 1 $iStringStart = StringInStr( _GUICtrlRichEdit_GetText($g_hRichEdit), $aMatches[$i], 0 , 1, $iOffset) - 1 $iStringEnd = $iStringStart + StringLen($aMatches[$i]) $iOffset = $iStringEnd $g_aRichEditFields[$i+1][0] = $aMatches[$i] $g_aRichEditFields[$i+1][1] = $iStringStart $g_aRichEditFields[$i+1][2] = $iStringEnd Next Return 1 EndFunc ;==>_GenerateRichEditFields Func _Exit() Exit EndFunc ;==>_Exit "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
caramen Posted October 4, 2020 Author Share Posted October 4, 2020 (edited) Bingo it's working nice. But now I have to understand what do you did. I never used ReDim And this return Thanks for help bro Edited October 4, 2020 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
caramen Posted October 4, 2020 Author Share Posted October 4, 2020 Ah it's hard for me, it does not fit to my main script. You changed the logic because I need to push Next to have all result highlighted and my main script use the logic one time like all my reproducer posted x). I have to rework your code but I don't understand it yet. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki 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