Jump to content
vin1

replace words in text with other words from a word list

Recommended Posts

vin1

i need a script that can replace words in text with other words from a words list

it has to have 2 edit boxes input/output and a button "run"

from word_list.txt it choses which word to replace with. words are separated with commas for multiple choice

 

Screenshot_3.png

 

 

Screenshot_4.png

 

 

; AutoIt GUI Example
; Created: 17/01/2005 - CyberSlug
; Modifed: 05/12/2011 - guinness
; Modifed: 09/06/2014 - mLipok

#Region INCLUDE
#include <AVIConstants.au3>
#include <GuiConstantsEx.au3>
#include <TreeViewConstants.au3>
#EndRegion INCLUDE

#Region GUI
GUICreate("Sample GUI", 400, 420)
GUISetIcon(@SystemDir & "\mspaint.exe", 0)
#EndRegion GUI



#Region EDIT
GUICtrlCreateEdit(@CRLF & "  Sample Edit Control", 10, 10, 380, 175)
GUICtrlSetTip(-1, '#Region EDIT')
#EndRegion EDIT

#Region EDIT2
GUICtrlCreateEdit(@CRLF & "  Sample Edit Control", 10, 185, 380, 175)
GUICtrlSetTip(-1, '#Region EDIT')
#EndRegion EDIT2

#Region BUTTON
GUICtrlCreateButton("Sample Button", 10, 360, 100, 30)
GUICtrlSetTip(-1, '#Region BUTTON')
#EndRegion BUTTON

#Region GUI MESSAGE LOOP
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

GUIDelete()
#EndRegion GUI MESSAGE LOOP

 

Edited by vin1

Share this post


Link to post
Share on other sites
Earthshine

well, you had better get busy with that :)

where is the code that does the selection and such that you have tried?  

I think a Moderator already has this covered....

This code is taken directly from that post--Written by Moderator @Melba23, for your convenience, and it works, I just tested it. You could the adapt the algorithm for your needs. but you would need an appropriate  array to store your data (or use a database, each word could have multiple records associated with it and do it that way).

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $cInput, $cList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)

$cInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$cList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$cButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$cUP = GUICtrlCreateDummy()
$cDOWN = GUICtrlCreateDummy()
$cENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $cUP], ["{DOWN}", $cDOWN], ["{ENTER}", $cENTER]]
GUISetAccelerators($AccelKeys)

$iCurrIndex = -1

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cList
            $sChosen = GUICtrlRead($cList)
            If $sChosen <> "" Then GUICtrlSetData($cInput, $sChosen)
        Case $cButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($cInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $cUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
        Case $cDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($cList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
        Case $cENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($cList, $iCurrIndex)
                GUICtrlSetData($cInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
    EndSwitch

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($cInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($cList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($cList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)

EndFunc   ;==>Keywords

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

     ; If it was an update message from our input
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $cInput Then
       CheckInputText()
    EndIf

EndFunc

 

 

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

also, sounds like you need a Dictionary (in your case a Thesaurus). check this thread

Code from sample that I tested. Works as Dictionary

#Include <GUIListBox.au3>

Global $Ini = @ScriptDir & "\Dictionary.ini"
Global $Found
Global $WordCount
IniWrite($Ini, "Dictionary", "", "")

$GUI = GUICreate("Dictionary", 474, 336)
GUICtrlCreateLabel("Search:", 0, 0, 48, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$SearchInput = GUICtrlCreateInput("", 0, 16, 121, 21)
$Search = GUICtrlCreateButton("Search", 120, 16, 43, 21, 0)
GUICtrlCreateLabel("Dictionary Entries:", 0, 40, 89, 17)
$DictionaryEntries = GUICtrlCreateList("", 0, 56, 121, 279)
$AddEntry = GUICtrlCreateButton("Add Entry", 120, 56, 75, 25, 0)
$DeleteEntry = GUICtrlCreateButton("Delete Entry", 120, 88, 75, 25, 0)
$EditEntry = GUICtrlCreateButton("Edit Entry", 120, 120, 75, 25, 0)
$PronounceEntryName = GUICtrlCreateButton("Pronounce Entry Name", 200, 56, 123, 25, 0)
$PronounceEntryDefinition = GUICtrlCreateButton("Pronouce Entry Definition", 200, 88, 123, 25, 0)
GUICtrlCreateLabel("Entry Definition:", 120, 152, 78, 17)
$EntryDefinition = GUICtrlCreateEdit("", 120, 169, 353, 163, 0x0004)
$About = GUICtrlCreateButton("About", 398, 0, 75, 25, 0)
_PopulateDictionaryList()
GUISetState(@SW_SHOW)

While 1
    WinSetTitle($GUI, "", "Dictionary - "&$WordCount&" words present.")
    Switch GUIGetMsg()
        Case - 3
            Exit
        Case $DictionaryEntries
            _GetDefinition()
        Case $Search
            _Search()
        Case $AddEntry
            _NewEntry()
        Case $DeleteEntry
            _DeleteEntry()
        Case $EditEntry
            _EditEntry()
        Case $PronounceEntryName
            $Speak = ObjCreate("Sapi.SPVoice")
            $Speak.Speak(GUICtrlRead($DictionaryEntries))
        Case $PronounceEntryDefinition
            $Speak = ObjCreate("Sapi.SPVoice")
            $Speak.Speak(GUICtrlRead($EntryDefinition))
        Case $About
            MsgBox(64, "About", "Dictionary copyright Justin Reno 2008.")
    EndSwitch
WEnd

Func _PopulateDictionaryList()
    If FileExists($Ini) Then
        If $WordCount <> "" Then $WordCount = ""
        $GetEntries = IniReadSection($Ini, "Dictionary")
        GUICtrlSetData($DictionaryEntries, "")
        For $A = 1 To $GetEntries[0][0]
            $WordCount += 1
            _GUICtrlListBox_AddString ($DictionaryEntries, $GetEntries[$A][0])
        Next
    EndIf
EndFunc   ;==>_PopulateDictionaryList

Func _GetDefinition()
    If FileExists($Ini) Then
        $GetEntries = IniReadSection($Ini, "Dictionary")
        For $B = 1 To $GetEntries[0][0]
            If $GetEntries[$B][0] = GUICtrlRead($DictionaryEntries) Then GUICtrlSetData($EntryDefinition, $GetEntries[$B][1])
        Next
    EndIf
EndFunc

Func _Search()
    If FileExists($Ini) Then
        $GetEntries = IniReadSection($Ini, "Dictionary")
        For $C = 1 To $GetEntries[0][0]
            If GUICtrlRead($SearchInput) = $GetEntries[$C][0] Then $Found = $GetEntries[$C][0]
        Next
        If $Found <> "" Then _GUICtrlListBox_SetCurSel ($DictionaryEntries, _GUICtrlListBox_SelectString ($DictionaryEntries, $Found))
    EndIf
EndFunc   ;==>_Search

Func _NewEntry()
    $GUI = GUICreate("New Entry", 122, 106, -1, -1, -1, 0x80)
    GUICtrlCreateLabel("Entry Word:", 0, 0, 60, 17)
    $EntryWord = GUICtrlCreateInput("", 0, 16, 121, 21)
    GUICtrlCreateLabel("Entry Definition:", 0, 40, 78, 17)
    $EntryDefinition = GUICtrlCreateInput("", 0, 56, 121, 21)
    $AddEntry = GUICtrlCreateButton("Add Entry", 0, 80, 121, 25, 0)
    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case - 3
                GUIDelete($GUI)
                ExitLoop
            Case $AddEntry
                If FileExists($Ini) Then
                    $GetEntries = IniReadSection($Ini, "Dictionary")
                    For $D = 1 To $GetEntries[0][0]
                        If $GetEntries[$D][0] = GUICtrlRead($EntryWord) Then
                            MsgBox(16, "Error", "Word to be added already exists!")
                            GUIDelete($GUI)
                            ExitLoop
                        EndIf
                    Next
                EndIf
                IniWrite($Ini, "Dictionary", GUICtrlRead($EntryWord), GUICtrlRead($EntryDefinition))
                If @Compiled = 0 Then Run(@AutoItExe & " " & FileGetShortName(@ScriptFullPath))
                If @Compiled = 1 Then Run (@ScriptFullPath)
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>_NewEntry

Func _DeleteEntry()
    If GUICtrlRead($DictionaryEntries) <> "" Then IniDelete($Ini, "Dictionary", GUICtrlRead($DictionaryEntries))
    _PopulateDictionaryList()
EndFunc

Func _EditEntry()
    $GUI = GUICreate("Edit Entry", 123, 106, -1, -1, -1, 0x80)
    GUICtrlCreateLabel("Entry Word:", 0, 0, 60, 17)
    $EntryWord = GUICtrlCreateInput(GUICtrlRead($DictionaryEntries), 0, 16, 121, 21)
    GUICtrlCreateLabel("Entry Definition:", 0, 40, 78, 17)
    $EntryDefinition = GUICtrlCreateInput("", 0, 56, 121, 21)
    $SaveEntry = GUICtrlCreateButton("Save Entry", 0, 80, 121, 25, 0)
    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case - 3
                GUIDelete($GUI)
                ExitLoop
            Case $SaveEntry
                IniWrite($Ini, "Dictionary", GUICtrlRead($EntryWord), GUICtrlRead($EntryDefinition))
                _PopulateDictionaryList()
                GUIDelete($GUI)
                If @Compiled = 0 Then Run(@AutoItExe & " " & FileGetShortName(@ScriptFullPath))
                If @Compiled = 1 Then Run (@ScriptFullPath)
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>_EditEntry

You can bend Dictionary.ini to your will look at it's structure and replace with your words and values.

Dictionary.ini

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
BrewManNH

If someone types a multi-word sentence in the first box, do you want to replace EVERY word in the sentence, some of the words, highlighted words, specific words? You're not giving us any help here. We'd need the word list, plus a lot of before and after examples of what you're looking to do.

Looking at your screenshot of the word list, I'd turn it into an INI file and work with that instead.

  • Like 1

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Melba23

vin1,

This looks like a basic plagiarism tool. Before we go any further, just exactly why do you want to do this?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
vin1

I'll use it to rewrite articles from online websites. I'll try to create a rephrase version that rearranges text differently than the source text

 

please help if possible

Edited by vin1

Share this post


Link to post
Share on other sites
Melba23

vin1,

So my guess was right. No help for you - write your own material. Thread locked.

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Similar Content

    • therks
      By therks
      I'm trying to create a simple clock widget that automatically scales the text to the size of the window. I came up with the following method, but it doesn't work as well as I'd like. It especially has trouble scaling to the width of the window for some reason (in the example, try resizing the window to be narrow and tall).
      Does anyone have a better method?
      #include <Misc.au3> #include <WinAPIConv.au3> #include <GUIConstants.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) Global $_FONT_FAMILY = 'Arial', $_LB_TEXT Main() Func Main() _GDIPlus_Startup() Local $hGUI GUIRegisterMsg($WM_SIZE, WM_SIZE) $hGUI = GUICreate('', 300, 100, Default, Default, $WS_OVERLAPPEDWINDOW, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) $_LB_TEXT = GUICtrlCreateLabel('This is a string', 0, 0, 300, 100, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont($_LB_TEXT, _MeasureString($hGUI, GUICtrlRead($_LB_TEXT), $_FONT_FAMILY), 0, 0, $_FONT_FAMILY, 5) GUISetState() Local $iGM While 1 $iGM = GUIGetMsg() Switch $iGM Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GDIPlus_Shutdown() EndFunc Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) GUICtrlSetFont($_LB_TEXT, _MeasureString($hWnd, GUICtrlRead($_LB_TEXT), $_FONT_FAMILY), 0, 0, $_FONT_FAMILY, 5) EndFunc Func _MeasureString($hWnd, $sString, $sFont = 'Arial') Local $iError, $aSize, $hGraphic, $hFormat, $hFamily, $tLayout, $iFontSize, $hFont, $aInfo If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) EndIf $aSize = WinGetClientSize($hWnd) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate($sFont) $tLayout = _GDIPlus_RectFCreate(0, 0, $aSize[0], $aSize[1]) $iFontSize = 0 Do If Not $hFamily Then $iError = 1 $iFontSize = 10 ExitLoop EndIf $iFontSize += 1 $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 0) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat) _GDIPlus_FontDispose($hFont) If $aInfo[1] = 0 Then ExitLoop Until DllStructGetData($aInfo[0], 3) >= $aSize[0] Or DllStructGetData($aInfo[0], 4) >= $aSize[1] $iFontSize -= 1 _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) Return SetError($iError, 0, $iFontSize) EndFunc
    • dadalt95
      By dadalt95
      Hi!
      I want to get the signal in this website:
      https://binary-signal.com/pt/chart/eurusd
      I have tried using _IEBodyReadText  and some _StringBetween. What happens is that the text are being update every tick and _IEBodyReadText doesn't.
      To perform the update I used  _IEAction($oIE, "refresh") but it's not good because the website block me after some time due too many requests..
      Is there any other way to get this text every tick?
      PS: The text I want to get is WAIT, CALL or PUT.
       
      Here is the code:
      global $oIE = _IECreate ('https://binary-signal.com/pt/chart/eurusd', 0, 1 , 1 , 0) Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') ;MsgBox ( 0, "asf", $result[0]) $espera=StringInStr($result[0], "WAIT") $compra=StringInStr($result[0], "CALL") $venda=StringInStr($result[0], "PUT") ;MsgBox($MB_SYSTEMMODAL, "", $espera) $n=0 $c=0 Captar() Func Captar() ;_IENavigate($oIE, "https://binary-signal.com/pt/chart/eurusd") ;MsgBox($MB_SYSTEMMODAL, "", $n) Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') If (Not $compra=0) And $n=0 Then MsgBox($MB_SYSTEMMODAL, "", "COMPRE") $n=1 $c=$c+1 ;_IEAction($oIE, "refresh") Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=0 Then MsgBox($MB_SYSTEMMODAL, "", "VENDA") $c=$c+1 $n=1 ;_IEAction($oIE, "refresh") ;MsgBox($MB_SYSTEMMODAL, "", $n) Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Esperando próxima rodada") $n=1 ;MsgBox($MB_SYSTEMMODAL, "", $n) ;_IEAction($oIE, "refresh") Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Esperando próxima rodada") $n=1 ;MsgBox($MB_SYSTEMMODAL, "", $n) ;_IEAction($oIE, "refresh") Sleep(60000) Captar() Else ;MsgBox("", "", "ESPERE") $n=0 Sleep(1000) ;_IEAction($oIE, "refresh") Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') Captar() EndIf EndFunc  
    • WoodGrain
      By WoodGrain
      Hi All,
      I'd like to replace 'COMMA' with ',' for example:
      $myString = "COMMA" StringRegExpReplace($myString, 'COMMA', ',') Now I've tried escaping the ',' in various ways unsuccessfully, such as:
      '[,]'
      "[,]"
      '\,'
      [,] seems to work in the pattern, I just can't figure out how to use it in the replace, and it seems everyone online is only interested in removing/replacing commas lol.
      I also tried creating and using a variable as the replacement but also didn't work:
      $myComma = "," $myString = "COMMA" StringRegExpReplace($myString, 'COMMA', $myComma) I'm sure it's super simple if someone could point me in the right direction - thanks.
    • Ambient
      By Ambient
      I have tried several way sto get this to work to no avail. Any help would be appreciated. #include <ListViewConstants.au3> #include <GuiListView.au3> #include "GuiListViewEx.au3" $idItem = GUICtrlCreateListViewItem($r & " | " & $c & $adoRs.Fields("TransactionAmount").value & " | " & $Timestamp & " | " & _StringProper($adoRs.Fields("Tillid").value) & @CRLF & @CRLF & "Card Number : " & $cardnum & " " , $idListView) ConsoleWrite( "IDITEM" & $idItem) If STRINGLEFT($adoRs.Fields("TransactionAmount").value,1)= "-" Then Consolewrite(" String is Negative" & @CRLF) ;Drops in Here as expected ;GUICtrlSetColor(-1, $COLOR_RED) ; Colour line if item is negative this didn' work $TxC= _GUICtrlListView_SetTextColor($hListView, $CLR_RED) ; I also tried $TxC= _GUICtrlListView_SetTextColor(-1, 0xFF0000) CONSOLEWRITE("TEXTCOLOUR RETURNED " & $TxC & @crlf) ; This is returning True ELSE Consolewrite(" String is NOT Negative" & @CRLF) EndIf  
    • AndyS19
      By AndyS19
      I want to copy just the selected text in an input control and put it to the clipboard, but GuiCtrlRead() always reads all of the text in the control.
      In this test code, when I highlight a  portion of the left control's text and press ^C, I want to copy just that text to the clipboard; but when I highlight a  portion of the right control's text and press ^C, I want to copy all of its text to the clipboard.
      #include <Debug.au3> _DebugSetup(@ScriptName & "_debug.txt", False, 2, "") _DebugOut("=============== " & @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " ====================") #include <GUIConstants.au3> #include <WinAPI.au3> #include <Array.au3> Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Set OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("Event_GUIClose") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Global $hWnd_MainWin, $iID_Left, $iID_Right _Main() Func _Main() $hWnd_MainWin = GUICreate("test7", 200, 300) $iID_Left = GUICtrlCreateInput("AAA BBB CCC (get Selected text)", 10, 30, 200, 25) GUICtrlSetOnEvent($iID_Left, "handle_left_btn") $iID_Right = GUICtrlCreateInput("DDD EEE FFF (get All text)", 10, 60, 200, 25) GUICtrlSetOnEvent($iID_Right, "handle_right_btn") Local $aAccelKeys[1][2] = [["^c", $hWnd_MainWin]] GUISetAccelerators($aAccelKeys) GUISetOnEvent($GUI_EVENT_CLOSE, 'Event_GUIClose') GUISetState() ; Make everything visible While 1 Sleep(127) WEnd EndFunc ;==>_Main Func handle_CTRL_C_key() ConsoleWrite("+++: handle_CTRL_C_key() entered" & @CRLF) Local $hCtrl, $ctrlID, $control_classname, $text $control_classname = ControlGetFocus($hWnd_MainWin) $hCtrl = ControlGetHandle($hWnd_MainWin, "", $control_classname) $ctrlID = _WinAPI_GetDlgCtrlID($hCtrl) If ($ctrlID = $iID_Left) Then $text = GUICtrlRead($ctrlID) ClipPut($text) ConsoleWrite("+++: Copied selected text:" & @CRLF & "==>" & $text & "<==" & @CRLF) ElseIf ($ctrlID = $iID_Right) Then $text = GUICtrlRead($ctrlID) ClipPut($text) ConsoleWrite("+++: Copied all text:" & @CRLF & "==>" & $text & "<==" & @CRLF) EndIf EndFunc ;==>handle_CTRL_C_key Func Event_GUIClose() Exit (99) EndFunc ;==>Event_GUIClose Func handle_left_btn() ConsoleWrite("+++: handle_left_btn() entered" & @CRLF) EndFunc ;==>handle_left_btn Func handle_right_btn() ConsoleWrite("+++: handle_right_btn() entered" & @CRLF) EndFunc ;==>handle_right_btn
       
×