Jump to content
Sign in to follow this  
Silverlode

Find a string in a ListBox

Recommended Posts

Silverlode

Hi,

I'm trying to find a string in a listbox and use if...then...else depending on whether an item is already in the listbox.  But I'm having a hard time getting my script to recognize the string, even if it's there.

I have a dialog called "Select Server" and am looking for a hostname in the listbox.  It wasn't working so I created a MsgBox to view the return.  It's always 0 no matter what:

WinActivate("Select Server", "")
$rtn00 = ControlCommand("Select Server", "", "ListBox1", "FindString", "slc05hcl")
MsgBox(0, "rtn", $rtn00)

As I understand it, if "slc05hcl" exists in ListBox1, then the 'occurrence ref' should be 1, right?  I'm getting 0 every time no matter what.

Share this post


Link to post
Share on other sites
jdelaney

Look in the helpfile, under _GUICtrlListBox_*

More options with those functions.

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.

Share this post


Link to post
Share on other sites
Silverlode

Thanks.  I tried using _GUICtrlListBox_FindString and I STILL get a return of 0 even if the explicit string is not there (whereas I should get a return of -1).  I can't explain this.

Share this post


Link to post
Share on other sites
jdelaney

Are you passing a handle into the function?  Show your work.  Use ControlGetHandle's return in those functions.

Also, output the data from the control tab of the window info tool, when focused on your control.

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.

Share this post


Link to post
Share on other sites
Silverlode

Here's the info summary:

>>>> Window <<<<
Title:  Select Server
Class:  #32770
Position:   567, 280
Size:   280, 293
Style:  0x94C800C4
ExStyle:    0x00010101
Handle: 0x000503E2

>>>> Control <<<<
Class:  ListBox
Instance:   1
ClassnameNN:    ListBox1
Name:   
Advanced (Class):   [CLASS:ListBox; INSTANCE:1]
ID: 4240
Text:   
Position:   11, 34
Size:   165, 143
ControlClick Coords:    49, 80
Style:  0x50010103
ExStyle:    0x00000204
Handle: 0x000203F8

>>>> Mouse <<<<
Position:   632, 440
Cursor ID:  0
Color:  0xFFFFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
&Server:
Make Default
&New...
&Delete
&Edit...
OK
Cancel


>>>> Hidden Text <<<<

 And the complete script:

; INCLUDES
#include <GuiListBox.au3>

; declare and define some variables
Global $dbase_name, $hsfserv
$dbase_name = "ecm_ba_db"
$hsfserv = "slc05hcl"

; launch HSF Admin
Run("C:\Oracle\Middleware\EPMSystem11R1\products\hsf\Client\bin\HSFAdmin.exe")
WinWait("Oracle Hyperion Strategic Finance Administrator", "")
WinSetState("Oracle Hyperion Strategic Finance Administrator", "", @SW_MAXIMIZE)

; CONNECT TO A SERVER
WinMenuSelectItem("Oracle Hyperion Strategic Finance Administrator", "", "&Server", "&Open")
WinWait("Oracle Hyperion Strategic Finance, Fusion Edition Log On")
ControlClick("Oracle Hyperion Strategic Finance, Fusion Edition Log On", "", "[ID:2715]")
WinWait("Select Server","")
; check to see if connection already exists.  if not, create it.
WinActivate("Select Server", "")
WinSetState("Select Server", "", @SW_SHOW)
$rtn00 = _GUICtrlListBox_SelectString ("ListBox1", $hsfserver)
MsgBox(0, "rtn", $rtn00)

$rtn00 should equal -1 if the $hsfserver is not in the list.  Instead, I get 0.

Share this post


Link to post
Share on other sites
jdelaney

Like I said, you need to pass in a handle, not the classNN to the _gui* functions.

$hListBox = ControlGetHandle("Select Server", "",4240)
$rtn00 = _GUICtrlListBox_SelectString ($hListBox, $hsfserver)

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.

Share this post


Link to post
Share on other sites
Silverlode

Thank you.  Clearly I'm new to all this.  That was it.

Share this post


Link to post
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
Sign in to follow this  

×