Posts: 62
Threads: 15
Joined: Mar 2009
Macro
Acc object=acc("Cell 900" "LISTITEM" win("Excel" "#32770") "SysListView32" "0/300" 0x1415)
object.Select(SELFLAG_TAKEFOCUS|SELFLAG_TAKESELECTION)
what i am trying to do is have accesible object select a "Random cell" (cells are numbered 1-900 as Cell 1,2 ect) In this example 900 is the object that has "Descr 0/300"
i was wondering on how to get it select a random cell between Cell 1-900 with descr "0/300"... i used this code and it will select the first one it finds and then not select any others.... is this possible? and if so how. Thanks as always G
Posts: 12,071
Threads: 140
Joined: Dec 2002
..acc(_s.format("Cell %i" RandomInt(1 900))...)
Posts: 62
Threads: 15
Joined: Mar 2009
Gintaras Wrote:..acc(_s.format("Cell %i" RandomInt(1 900))...)
sorry i dont understand what im sapose to do...
Posts: 12,071
Threads: 140
Joined: Dec 2002
_s.format("Cell %i" RandomInt(1 900))
will generate a random number in place of "Cell 900". Eg "Cell 276", "Cell 321"...
Posts: 62
Threads: 15
Joined: Mar 2009
Gintaras Wrote:_s.format("Cell %i" RandomInt(1 900))
will generate a random number in place of "Cell 900". Eg "Cell 276", "Cell 321"...
ok then do i put that string into the part of accesible object where "cell 900" is already? and is there a way to make it get random number after the first 3 didgets? so if 100983474 is the number it will get 10048322993 or 100999922?
Posts: 12,071
Threads: 140
Joined: Dec 2002
Yes, replace "Cell 900" to _s.
Posts: 62
Threads: 15
Joined: Mar 2009
Gintaras Wrote:Yes, replace "Cell 900" to _s.
ok i was just trying the code out.. there is a problem. it dont work half the time because a lot of the time the number it looks for isnt found. (dont exist) is there anyway to fix that? Its looking for the number in a class "SysListView32" and role "LISTITEM" .. any ideas?
Posts: 45
Threads: 13
Joined: Jul 2009
Yes you can make it if it errors retry
like
Function
Function
START
_s.format("Cell %i" RandomInt(1 900))
Acc object=acc(_s "LISTITEM" win("Excel" "#32770") "SysListView32" "0/300" 0x1415)
err
,goto START
object.Select(SELFLAG_TAKEFOCUS|SELFLAG_TAKESELECTION)
That should work
Posts: 62
Threads: 15
Joined: Mar 2009
sorry still dont work..... well mabey this will solve my problem... is there a way to make it select the list item with descr 0/300 and then select another one just making it so its not the same one? cause that is my problem. it keeps selecting the exact same one.
Posts: 12,071
Threads: 140
Joined: Dec 2002
another way
Macro
Macro807
out
;find accessible object of listview control (in the example I use QM My Macros dialog, change it)
int w1=win(" - My Macros - All Programs" "#32770")
Acc ao=acc("" "LIST" w1 "SysListView32" "" 0x1000)
;get item count
int n=SendMessage(child(ao) LVM_GETITEMCOUNT 0 0)
;store elem of all items with certain description to array a (in the example I use "*0" as description, change it)
ARRAY(int) a
int i
for i 0 n
,ao.elem=i+1
,str sd=ao.Description
,;out sd
,if(!matchw(sd "*0")) continue
,a[]=ao.elem
out "found %i matching items" a.len
;randomize the array
a.shuffle
;now select items. The code selects different item every 1 s.
act w1
for i 0 a.len
,ao.elem=a[i]
,out ao.Name
,ao.Select(SELFLAG_TAKEFOCUS|SELFLAG_TAKESELECTION)
,1
Posts: 62
Threads: 15
Joined: Mar 2009
that works perfect G! only thing is can u change it so it dont select every second and just selects based on a rep? thanks G!
Posts: 12,071
Threads: 140
Joined: Dec 2002
Posts: 62
Threads: 15
Joined: Mar 2009
like
spe 1
rep
code u gave me 2823
422932
instead of doing it every 1 second it does it every rep
Posts: 12,071
Threads: 140
Joined: Dec 2002
replace
for i 0 a.len
to
i=RandomInt(0 a.len-1)
Posts: 62
Threads: 15
Joined: Mar 2009
Thank you so much... now if i was to put the rep in.. where should i put?
Posts: 62
Threads: 15
Joined: Mar 2009
having problems with it failing to find object. sometimes the window is minimized and not showing would that make the function fail? Cause most the time window isnt visible (Showing on desktop) when calling for the code. thanks
Posts: 12,071
Threads: 140
Joined: Dec 2002
Yes, accessible object functions may fail if the object is not visible. acc has a flag 16 "include invisible objects", try it. Select often fails if the windows is not active.
Posts: 62
Threads: 15
Joined: Mar 2009
found out if u use this code with the label it helps it if it fails. dont stop the macro
label 1
acc object code.... *special code
err
goto label 1