Jump to content

How to Highlight text into InputBox


Recommended Posts

Is it better this way ?

[...]

            Case $idBtnNext
                If $g_bMatchesFound Then
                    While $g_iIndex <= $g_aRichEditFields[0][0]
                        _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
                    WEnd
                    $g_iIndex = 1

                EndIf

[...]

 

Musashi-C64.png

"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

Haha damn nice ! :) 

 

Sir I need to understand ! 

 

I will read carefully but later, two days now I'm on this. I will keep you posted here if you don't mind or if you allow me to pm you in case of need.

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 - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

2 hours ago, caramen said:

... or if you allow me to pm you in case of need.

Permission is hereby given ;).

Musashi-C64.png

"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

Here is a commented version that will hopefully help you further :

#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
; Description :
; 1. $g_hRichEdit : the text(string) you want to analyze, using a regular expression.
; 2. $g_sSearchPattern : the regular expression to match (pattern).
; 3. $g_aRichEditFields[0][3] :
;       a two dimensional "one-based"-array, which means that the data starts in Row 1.
;       Row 0 [0][0] contains the number of 'data-rows'
;       Row 1, Element 1 (Index 0) ==> [1][0] = Match 1
;       Row 1, Element 2 (Index 1) ==> [1][1] = Startposition in text
;       Row 1, Element 3 (Index 2) ==> [1][2] = Endposition in text
;       Row 2 ...
;    The function _GenerateRichEditFields() populates this array with data. 
; 4. $g_iIndex : global helper index for accessing the desired row.
; 5. $g_bMatchesFound : False, if no matches were found, otherwise True.

$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
                    
                    ; Variation 1 :
                    ; -------------
                    ; The matches will be colored STEP by STEP if the Next button is pushed.
                    ;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
                    

                    ; Variation 2 :
                    ; -------------
                    ; ALL matches will be colored if the Next button is pushed.
                    While $g_iIndex <= $g_aRichEditFields[0][0]
                        _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
                    WEnd
                    $g_iIndex = 1

                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example


Func _GenerateRichEditFields()
    Local $aMatches, $iStringStart, $iStringEnd, $iOffset = 1
    
    ; Check if the search pattern ($g_sSearchPattern) was found. Matches are stored in an array.
    ; If there are no matches, the function will be exited with the return value 0.
    $aMatches = StringRegExp(_GUICtrlRichEdit_GetText($g_hRichEdit), $g_sSearchPattern , 3)
    If @error Then Return 0

    ; Redimension of the array $g_aRichEditFields (the size is now known)
    ReDim $g_aRichEditFields[UBound($aMatches) + 1][3]
    $g_aRichEditFields[0][0] = UBound($aMatches)

    ; To find multiple (identical) matches, the starting position (offset) within StringInStr
    ; is increased. Parts of the already searched string are thereby skipped.
    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

If you have further questions, you are welcome to write me a PM, as already mentioned ;).

Musashi-C64.png

"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

It's Ok :) I already did a function to implement it with multiple

$g_sSearchPattern
Func _GenerateRichEditFields($g_sSearchPattern)

Thanks for all mate :) 

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 - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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