jfcby Posted January 11, 2010 Share Posted January 11, 2010 (edited) Hi,I'm trying to figure out how to select a word in an edit control.I've looked in the help file at the: 1. PosFromChar and CharFromPos2. SetSel, GetSel, and SetTextBut with each of these you need the start character position and the end character position. I do not understand how to get them with the following code.How do you get the character positions using this part of the code:$array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset)Full Code:expandcollapse popup#include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <GuiEdit.au3> Global $msg $hWidth = 395 $hHeight = 425 $hLeft = $hWidth / 2 $hTop = $hHeight / 2 $hGUI = GUICreate("Select Word In Edit Control Example", $hWidth, $hHeight, (@DesktopWidth / 2) - $hLeft, (@DesktopHeight / 2) - $hTop) $Label1 = GUICtrlCreateLabel("Editor", 5, 1, 100, 15) GUICtrlSetFont(-1, 9, 600) $Edit1 = GUICtrlCreateEdit("Coutn adn splel", 5, 25, 385, 350, _ BitOR($ES_AUTOVSCROLL, $ES_MULTILINE, $ES_NOHIDESEL, $ES_WANTRETURN)) $Button1 = GUICtrlCreateButton("Select Word", 325, 380) GUISetState() $nOffset = 1 While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE Exit Case $Msg = $Button1 _SelectWord() EndSelect WEnd Func _SelectWord() ;Select individual word. $array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset) If @error = 0 Then $nOffset = @extended Else ;ExitLoop EndIf For $i = 0 to UBound($array) - 1 MsgBox(0, "RegExp Test with Option 1 - " & $i, $array[$i] & @CRLF) ConsoleWrite("RegExp Test with Option 1 - " & $i & " " & $array[$i] & @CRLF) Next EndFunc ;==>_SelectWordUpdate 1/11/2010: For full example code go to: Xamp Spell Check Edited January 11, 2010 by jfcby Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB **** Link to comment Share on other sites More sharing options...
martin Posted January 11, 2010 Share Posted January 11, 2010 Not sure if this is what you are after, but maybe it helps. expandcollapse popup#include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <GuiEdit.au3> Global $msg $hWidth = 395 $hHeight = 425 $hLeft = $hWidth / 2 $hTop = $hHeight / 2 $hGUI = GUICreate("Select Word In Edit Control Example", $hWidth, $hHeight, (@DesktopWidth / 2) - $hLeft, (@DesktopHeight / 2) - $hTop) $Label1 = GUICtrlCreateLabel("Editor", 5, 1, 100, 15) GUICtrlSetFont(-1, 9, 600) $Edit1 = GUICtrlCreateEdit("Coutn adn splel", 5, 25, 385, 350, _ BitOR($ES_AUTOVSCROLL, $ES_MULTILINE, $ES_NOHIDESEL, $ES_WANTRETURN)) $Button1 = GUICtrlCreateButton("Select Word", 325, 380) GUISetState() $nOffset = 1 While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE Exit Case $Msg = $Button1 _SelectWord() EndSelect WEnd Func _SelectWord() ;Select individual word. $array = StringRegExp(GUICtrlRead($Edit1), "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3, $nOffset) If @error = 0 Then $nOffset = @extended Else ;ExitLoop EndIf Local $sText = guictrlread($Edit1) Local $iTextLen = StringLen($sText) Local $from = 1;we search from here in edit text Local $ist;where we found the start of the word For $i = 0 to UBound($array) - 1 $ist = stringinstr($sText,$array[$i],0,1,$from,$iTextLen) - 1 $from = $ist + stringlen($array[$i]) _GUICtrlEdit_SetSel($Edit1,$ist,$ist+stringlen($array[$i])) MsgBox(0, "RegExp Test with Option 1 - " & $i, $array[$i] & @CRLF) ConsoleWrite("RegExp Test with Option 1 - " & $i & " " & $array[$i] & @CRLF) Next EndFunc ;==>_SelectWord 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 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