Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Acc Objects error?
#1
Macro
Code:
Copy      Help
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
#2
..acc(_s.format("Cell %i" RandomInt(1 900))...)
#3
Gintaras Wrote:..acc(_s.format("Cell %i" RandomInt(1 900))...)
sorry i dont understand what im sapose to do...
#4
_s.format("Cell %i" RandomInt(1 900))

will generate a random number in place of "Cell 900". Eg "Cell 276", "Cell 321"...
#5
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?
#6
Yes, replace "Cell 900" to _s.
#7
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?
#8
Yes you can make it if it errors retry

like

Function Function
Code:
Copy      Help
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
#9
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.
#10
another way
Macro Macro807
Code:
Copy      Help
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
#11
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!
#12
based on a rep?
#13
like
spe 1
rep
code u gave me 2823
422932


instead of doing it every 1 second it does it every rep
#14
replace

for i 0 a.len

to

i=RandomInt(0 a.len-1)
#15
Thank you so much... now if i was to put the rep in.. where should i put?
#16
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
#17
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.
#18
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


Forum Jump:


Users browsing this thread: 1 Guest(s)