Jump to content

Help outsmarting this stupid program...


 Share

Recommended Posts

Hey guys, so I have this really old program that I'm trying to 'upgrade' for my purposes.. I have realized that using a ControlGetText, I can read how many files are selected (aka how many files I want to export). I have automated the exporting process, and can loop it X amount of times.. but selecting the FIRST file to send out is driving me nuts. The only way I can figure to select the lowest file (so I can repeat up in my function) is to send a "Down" then "Up" which should highlight the selected files and basically only highlight the lowest file that is selected... And that works great.. but only if I SELECT the files from top to bottom so that the bottom file is the last thing clicked on.. Otherwise it will start from the top (See GIF). If you see the faint dotted line.. that's where it starts from.. any ideas guys?

#include <Array.au3>
WinActivate("Chromatogram open")
AutoItSetOption("SendKeyDelay", 150)
local $textgrab = ControlGetText("Chromatogram open","", "Static3")
Local $offiletoload=StringSplit($textgrab, " ", 2)
    ControlClick("Chromatogram open", "", "Edit1", "primary", 1)
    Send("{Tab}")
    Send("{Down}")
    Send("{Up}")
    Send("{SHIFTDOWN}")
For $i = 1 To $offiletoload[0]-1
    Send("{Up}")
Next
    Send("{SHIFTUP}")

problem.gif

Edited by BatMan22
Link to comment
Share on other sites

More reliable, use the _guictrllistview_* functions.

Look at the help file for (click this link):

_GUICtrlListView_SetItemSelected

This will also work if you ever want to run your script behind a desktop...such as when logged off.  Sends will not work in those cases.

Example:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $idListview

    GUICreate("ListView Set Item Selected", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268,$LVS_REPORT)
    GUISetState(@SW_SHOW)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Items", 100)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Item 1")
    _GUICtrlListView_AddItem($idListview, "Item 2")
    _GUICtrlListView_AddItem($idListview, "Item 3")

    ; Select item 2
    _GUICtrlListView_SetItemSelected($idListview, 1) ; select the second item
    _GUICtrlListView_SetItemSelected($idListview, 2) ; select the third item
    MsgBox($MB_SYSTEMMODAL, "Information", "Item 2 Selected: " & _GUICtrlListView_GetItemSelected($idListview, 1))

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

This is a VERY dumb example...you probably want to select specific files, yes?  There are other _guictrllistview functions to get the text, you can loop through until you find it, and the select it.

Edit...maybe that's a listbox...if that's the case, use this instead:

_GUICtrlListBox_SetSel
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $idListBox

    ; Create GUI
    GUICreate("List Box Set Sel", 400, 296)
    $idListBox = GUICtrlCreateList("", 2, 2, 396, 296, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    GUISetState(@SW_SHOW)

    ; Add strings
    _GUICtrlListBox_BeginUpdate($idListBox)
    For $iI = 1 To 9
        _GUICtrlListBox_AddString($idListBox, StringFormat("%03d : Random string", Random(1, 100, 1)))
    Next
    _GUICtrlListBox_EndUpdate($idListBox)

    ; Select a few items
    _GUICtrlListBox_SetSel($idListBox, 3)
    _GUICtrlListBox_SetSel($idListBox, 4)
    _GUICtrlListBox_SetSel($idListBox, 5)

    ; Show the item selection state
    MsgBox($MB_SYSTEMMODAL, "Information", "Item 5 Selected: " & _GUICtrlListBox_GetSel($idListBox, 4))

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Use the spy tool to figure out what control type it is.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

My final script, reads the guicontrollistbox, unselects all of them first then reselects them. Thank you @jdelaney, this way errors are a lot less likely! you rock!

#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <GuiListBox.au3>

$handl = ControlGetHandle("Chromatogram open", "", "ListBox1")
For $i = 0 To 10
    ConsoleWrite("Item#" & $i & " is Selected: " & _GUICtrlListBox_GetSel($handl, $i) & @CRLF)
Next

$selected = _GUICtrlListBox_GetSelItems($handl)

If UBound($selected) <> 1 Then
    Local $i
    For $i = 1 To $selected[0]
        ;sleep(200)
        _GUICtrlListBox_SetSel($handl, $selected[$i])
        ;sleep(200)
    Next

    For $i = 1 To $selected[0]
        _GUICtrlListBox_SetSel($handl, $selected[$i])
        ConsoleWrite("Item Selected: " & $selected[$i] & @CRLF)
    Next
Else
    MsgBox(0, 0, "You haven't chosen any files!")
EndIf

 

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