Jump to content

Fill Edit Box with _GUICtrlEdit_SetText troubles


l3ill
 Share

Recommended Posts

Maybe somebody can tell me why this Func works:

Func  _showSelected()
               $sSelect = "C:\Users\billo\Desktop\AutitScripts\AutoIT_v3_PenDrive\Examples\Helpfile\_IEFormElementSetValue.au3"
    _GUICtrlEdit_SetText($hEdit, FileRead($sSelect))
EndFunc

And this one doesn't

Func  _showSelected()

         $iSelect = ControlListView($Form1, "", $FoundList, "GetSelected")
         ConsoleWrite("$iSelect" & $iSelect & @CR)
         $sSelect = ControlListView($Form1, "", $FoundList, "GetText", $iSelect)
         ConsoleWrite("$sSelect" & $sSelect & @CR)

    _GUICtrlEdit_SetText($hEdit, FileRead($sSelect))
EndFunc

Without having to post the entire script?

$hEdit is a standard GUI Edit box

The console view of $sSelect is exactly the same as above $sSelect wout the quotes.

$FoundList is only a list of paths similar to the $sSelect in the first script.

I thought it might have something to do with quotes but I have tried bunches of tricks and nothing...

Any suggestions are welcome...

Thanks,

Bill

Link to comment
Share on other sites

What does $sSelect contain before you try writing it to the edit control? Also, is this listview an AutoIt listview or an externally created one?

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

My question dealt with what does $sSelect contain after doing "$sSelect = ControlListView($Form1, "", $FoundList, "GetText", $iSelect)"

The second question dealt with your use of ControlListView, why aren't you using _GUICtrlListView_GetItemText or _GUICtrlListView_GetItemTextArray or _GUICtrlListView_GetItemTextString, as I think they'd be more reliable.

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

 

My question dealt with what does $sSelect contain after doing "$sSelect = ControlListView($Form1, "", $FoundList, "GetText", $iSelect)"

The console view of $sSelect is exactly the same as above $sSelect wout the quotes:

C:\Users\billo\Desktop\AutitScripts\AutoIT_v3_PenDrive\Examples\Helpfile\_IEFormElementSetValue.au3

 

The second question dealt with your use of ControlListView, why aren't you using _GUICtrlListView_GetItemText or _GUICtrlListView_GetItemTextArray or _GUICtrlListView_GetItemTextString, as I think they'd be more reliable.

All these you mention give me the "path" in this case, which I already have.

I want to take the path to the file and using FileRead populate the edit box with the text file itself.

As I mentioned above it is probably some problem with the code not passing the path variable correctly to the _GUICtrlEdit_SetText 

Since the static path works and the var doesn't ?

Edit: Maybe the quotes?

Edited by billo
Link to comment
Share on other sites

I just tried this

$sSelect = '"' & $sSelect & '"'

and got this:

$sSelect"C:\Users\Badass\Desktop\BackUp\FileRead_WriteLine_Working_old8.au3
"

any variations that might keep the quote from dropping?

or wouldn't this matter?

added for clarity:

$sSelect = ControlListView($Form1, "", $FoundList, "GetText", $iSelect)
         ConsoleWrite("$sSelect: " & $sSelect & @CR)
         $sSelect = '"' & $sSelect & '"'
          ConsoleWrite("$sSelect: " & $sSelect & @CR)

console output:

$sSelect: C:\Users\Badass\Desktop\_FindInFile.au3

$sSelect: "C:\Users\Badass\Desktop\_FindInFile.au3
"
+>19:56:43 AutoIt3.exe ended.rc:0
Edited by billo
Link to comment
Share on other sites

FileRead won't work with a quoted path, e.g. ""C:SomePath"", so I don't think the quotes are the problem.

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

It looks like that string contains a CRLF or at least some kind of carriage return/line feed character which is probably why it's not working.

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

Perhaps someone knows an alternative to ControlListView & GetSelected | GetText

to turn the selected list view item into a usable variable?

 

If you test >this script you can see that the funtion works but not altogether correctly as it opens an additional tab in scite for no apparent reason.

I assume whatever is causing that behavior in scite is the problem here as well.

any other takers?

Link to comment
Share on other sites

I gave you 3 functions that would easily replace controllistview, why aren't they usable?

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

I stopped playing with them when I couldn't find a way for them to GetSelected listview item.

Getting the selected listview item wasn't the problem.

The problem was getting the selected listview item to the _GUICtrlEdit_SetText and through the FileRead as a variable.

Edited by billo
Link to comment
Share on other sites

_GUICtrlListView_GetSelectedIndices will tell you which item(s) are selected, that gives you the index number to use with one of the functions I posted above.

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

Perhaps more elegant but still the same issue.

After all the troubleshooting  (and it has been plenty) I always come back to this problem:

FileRead is not reading the $sSelect Variable. I can slip the static path in there and it works like a charm.

So the question:

How can I turn this:

$sSelect = C:\Users\Badass\Desktop\AutitScripts\AutoIT_v3_PenDrive\Examples\Helpfile\_IEFormElementSetValue.au3

Into this:

$sSelect = "C:\Users\Badass\Desktop\AutitScripts\AutoIT_v3_PenDrive\Examples\Helpfile\_IEFormElementSetValue.au3"

and just FYI this didn't work:

$sSelect = ('"'&  $sSelect  &'"')

console output

$sSelect: "C:\Users\Badass\Desktop\AutitScripts\AutoIT_v3_PenDrive\Examples\Helpfile\AutoItSetOption.au3
"

Any tip would be greatly appreciated :) 

Bill

Link to comment
Share on other sites

Did you read what I wrote in post #8? That string has a line feed of some sort at the end of it, as you can see because the quote is on the second line, and not at the end of the first line. Also, as also stated, FileRead will not work with a quoted path, so don't use quotes around the path and file name.

In other words this will work.

$sSelect ="C:\Users\Badass\Desktop\AutitScripts\AutoIT_v3_PenDrive\Examples\Helpfile\AutoItSetOption.au3"
ConsoleWrite(FileRead($sSelect) & @CRLF)

But this will not

$sSelect = "C:\Users\Badass\Desktop\AutitScripts\AutoIT_v3_PenDrive\Examples\Helpfile\AutoItSetOption.au3"
$sSelect = '"' & $sSelect & '"'
ConsoleWrite(FileRead($sSelect) & @CRLF)

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

BrewManNH,

  I have read all your posts with a fine tooth comb looking for a possible soultion.

Your last post is almost a carbon copy of my first post.


$sSelect ="C:UsersBadassDesktopAutitScriptsAutoIT_v3_PenDriveExamplesHelpfileAutoItSetOption.au3"

 

Yes. A static path will work.

Getting the path via selected or other however does not.

 

Also, as also stated, FileRead will not work with a quoted path

 Understood.

Not argueing this fact. But, the only difference between the console output for the static and  the select gotten varaible are the quotes.

The one with quotes works and the one without quotes  doesnt.

Not saying this is the problem....

Thanks anyway for all your time and help.

Bill

Edited by billo
Link to comment
Share on other sites

I just noticed last night that this in the wrong Forum - should've been in GUI H&S...my apoligies.

I have made a few changes and tried some other stuff and I am still here where I was.

But I did get it where it is postable for anyone to test, maybe now someone will be able to point me to the error of my ways.

GUI is still deeper water for me and this has got me stumped.

  • Put this code in any folder where you have some scripts and run it 
  • "Get Files" should populate the ListView
  • Now when you select one of the files there are 2 options:
  1. Open in Scite - sorta works but opens an extra tab for some reason - not the problem
  2. Preview - should populate the edit box with the text from the selected file - but it doesnt. { the problem  }

Thanks in advance for any help!

Bill

#include <Array.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>
Local $showText = ""
Local $sFolder = @ScriptDir ; works as browser in any folder you put the script in
$Form1 = GUICreate("SnippetBrowser", 810, 680, 246, 140, $WS_SIZEBOX, $WS_EX_ACCEPTFILES)
$Input1 = GUICtrlCreateInput("search", 10, 16, 180, 21)
$sBlistView = GUICtrlCreateListView("Path", 10, 45, 790, 353, 0x200)
_GUICtrlListView_SetColumnWidth($sBlistView, 0, 300)
;$sBlistView = _GUICtrlListView_Create($Form1, "Script", 10, 45, 790, 353, $LVS_LIST)
$getFiles = GUICtrlCreateButton("Get Files", 210, 14, 81, 25)
GUICtrlSetState($getFiles, $GUI_DEFBUTTON)
$ClearAll = GUICtrlCreateButton("Clear All", 310, 14, 81, 25)
$Dummy = GUICtrlCreateButton("Dummy", 410, 14, 81, 25)
$showSelected = GUICtrlCreateButton("Preview", 460, 405, 91, 25)
$label1 = GUICtrlCreateLabel($sFolder, 510, 20, 400, 25)
GUICtrlSetData($label1, $sFolder)
$openSelected = GUICtrlCreateButton("Open in SciTE", 360, 405, 91, 25)
;$hEdit = _GUICtrlEdit_Create($Form1, $showText, 10, 440, 790, 235)
$hEdit = GUICtrlCreateEdit("", 10, 440, 790, 235)
GUISetState(@SW_SHOW, $Form1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $getFiles
            _getFiles()

        Case $openSelected
            _openSelected()
        Case $ClearAll
            _GUICtrlListView_DeleteAllItems($sBlistView)
        Case $showSelected
            _showSelected()
    EndSwitch
WEnd

Func _getFiles()
    Global $FileList_A = _FileListToArray($sFolder, "*au3", 1)
    ;_ArrayDisplay($FileList_A)
    $rows = UBound($FileList_A)
    For $i = 0 To $rows - 1
        _GUICtrlListView_AddItem($sBlistView, $FileList_A[$i] & @LF)
        ConsoleWrite("$FileList_A[$i]: " & $FileList_A[$i] & @CR)
    Next
EndFunc   ;==>_getFiles
;================================================================  Trouble Zone
Func _showSelected()
    $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True) ;  works
    $sSelect = _GUICtrlListView_GetItemTextString($sBlistView, $iSelect[1])  ;  works
    ConsoleWrite("$sSelect: " & $sSelect & @CR)         ; somewhere between here
    _GUICtrlEdit_SetText($hEdit, FileRead($sSelect))    ; and here is a bugger

EndFunc   ;==>_showSelected
;================================================================  Trouble Zone
Func _openSelected()
    $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True)
    $sSelect = _GUICtrlListView_GetItemTextString($sBlistView, $iSelect[1])
    ConsoleWrite("$sSelect: " & $sSelect & @CR)
    $SciTE = @ProgramFilesDir & "\AutoIt3\SciTE\SciTE.exe"
    ShellExecute($SciTE, $sSelect)
EndFunc   ;==>_openSelected

Edited by billo
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...