Jump to content

Replace string in highlighted text


Recommended Posts

I have a field on the screen that I would like to replace some text.

The highlighted text is the string I would like to find and replace text in.

The text I would like to replace is "C:Program FilesText"

The text I would like to replace it with is what is in the variable &ProgramFiles.

Local &text = StringReplace("highlighted text", "C:\Program Files\Test", $ProgramFiles)

How can I get the highlighted text into the code StringReplace?

Thanks,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

Hi,

In AutoIt, a variable is prefixed by a dollar $. (More than 2 hundred posts and you make that mistake ?  :blink: ) and your code should work.

Edit: It shows that you have not made any effort to look at the helpfile or anywhere else.

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

I am very sorry I made a mistake with the $.  I don't see how the highlighted text is going to jump into the one line of code I have.

I have made a lot of effort to search the help file and the internet.  I still don't find a way to bring in text that is on the screen highlighted.

Thanks,

Docfxit

Link to comment
Share on other sites

I think I may have found a way to get the highlighted text off the screen.

I can't test it because I have errors that I can't figure out why.

This is the code I have:

; Include User.INI Info
#include "IniRead.au3"
Opt("WinWaitDelay", 100)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)
AutoItWinSetTitle(@ScriptName)
; AutoItSetOption("SendKeyDelay", 20)
AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number
Dim $highlightedtext

If _OSVersion() = 'Win7' Or _OSVersion() = 'Win7SP1' Or _OSVersion() = 'Win7X64' Or _OSVersion() = 'Win7SP1x64' Then
    $ProgramFiles = "C:\Programs\"
Else
    $ProgramFiles = "C:\Program Files\"
EndIf
Run('C:\Dnload\9xAddons\WordPerfect Office X6 v16.0.0.318\Setup.exe')
WinWait("WordPerfect Office X6", "")
If Not WinActive("WordPerfect Office X6", "") Then WinActivate("WordPerfect Office X6", "")
WinWaitActive("WordPerfect Office X6", "")
Send("{ALTDOWN}a{ALTUP}{ALTDOWN}n{ALTUP}{ALTDOWN}n{ALTUP}{ALTDOWN}u{ALTUP}{ALTDOWN}r{ALTUP}")
Send("{TAB}")
MsgBox(48, "Before Run", $highlightedtext)
$highlightedtext = _GetTextFromActiveWindow()
MsgBox(48, "After Run", $highlightedtext)

Local & text = StringReplace($highlightedtext, "C:\Program Files\Corel", $ProgramFiles)
Exit

Func _OSVersion()
    Local $OS_Version, $servicepack_version
    $OS_Version = StringStripWS(StringRegExpReplace(@OSVersion, "(WIN_)|(Microsoft )|(Windows )|(\(TM\))|( Ultimate)", ""), 8)
    $OS_Version = StringRegExpReplace(StringRegExpReplace($OS_Version, '2008', 'Win7'), 'VISTA', 'Vista')
    If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", 'CurrentBuildNumber') > 7000 Then $OS_Version = 'Win7'
    $servicepack_version = StringReplace(@OSServicePack, "Service Pack ", "SP")
    If @error = -1 Then $servicepack_version = ""

    ConsoleWrite($OS_Version & $servicepack_version & StringRegExpReplace(@OSArch, '(X86)', '') & @CRLF)
    Return $OS_Version & $servicepack_version & StringRegExpReplace(@OSArch, '(X86)', '')
EndFunc   ;==>_OSVersion

Func _GetTextFromActiveWindow()
    ;Get window title, in case we need it
    $window_title = WinGetTitle("[active]")
    If $window_title == "" Then
        SoundPlay(@WindowsDir & "\media\Windows XP Error.wav", 1)
        Exit
    EndIf
    WinActivate($window_title)
    ClipPut("") ;Clear the clipboard, so we can check for data when we write to it
    $readtext = "" ;We'll put new clipboard data in this variable
    For $i = 1 To 8 Step 1
        $rand = Random(1, 4, 1)
        Send("{CTRLDOWN}")
        ;Try various methods until we get text on the clipboard
        Switch $rand
            Case 1
                Send("{INS}")
            Case 2
                ControlSend($window_title, "", "", "{INS}")
            Case 3
                Send("c")
            Case 4
                ControlSend($window_title, "", "", "c^")
        EndSwitch
        Send("{CTRLUP}")
        $readtext = ClipGet() ;Any text on the clipboard?
        If $readtext <> "" Then
            Return $readtext
        EndIf
        If $i = 4 Then
            WinActivate($window_title)
            Sleep(100)
        EndIf
    Next
    Return $readtext
EndFunc   ;==>_GetTextFromActiveWindow

 

The first error I have is both of the functions show "undefined function".  I don't see why.  They look fine to me.

The second error I have is a "syntax error" on the StringReplace line 28.

Could someone please help me resolve these errors?

Thank you,

Docfxit

Link to comment
Share on other sites

The undefined function message is because of the line just before your _OSVersion function, it's written wrong so it's screwing up the parsing of the script.

Which brings us to the error on line 28, what exactly is that line supposed to be doing? Because it's written wrong for whatever it is. Maybe you meant to put a "$" in front of the variable text instead of the "&"?

Also, what is the purpose of this section of code?

 
If _OSVersion() = 'Win7' Or _OSVersion() = 'Win7SP1' Or _OSVersion() = 'Win7X64' Or _OSVersion() = 'Win7SP1x64' Then
    $ProgramFiles = "C:\Programs\"
Else
    $ProgramFiles = "C:\Program Files\"
EndIf

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

Link to comment
Share on other sites

Thank you for the reply...

I corrected the line before Func _OSVersion()

On line 28 what I would like is for it to replace the string in the $highlightedtext on the screen that looks like

"C:\Program Files\Corel" with what ever is in $ProgramFiles

That section of code figures out if I am running any flavor of Windows 7.  If I am I want to use the folder name "C:Programs".  If it's not Windows 7 I use the folder name "C:Program Files"

Thanks,

Docfxit

Link to comment
Share on other sites

@OSVersion will tell you if you're running any version of Windows 7 by returning WIN_7 as its value, there's no need to get fancy by trying to figure out which version of Win7 you're running because they're all Win7.

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

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