| || |
I'm trying to create a function that half the time needs to be called with tpAttachNoWait, and the other half with tpAttachNoWait & tpAttachChild. Is there any way to save the tpattachflags as a variable so that I can simply supply the function with a boolean to determine which flags to use?
The following is what i'm hoping for (this doesn't work)
<font class="small">Code:</font><hr /><pre>
public function findAThing(findChildren as boolean)
dim myFlags as tpattachflags
myFlags = tpAttachNoWait & tpAttachChild
myFlags = tpAttachNoWait
findAThing = object(innertext='Thing', myFlags)
Use + instead of & to combine the flags, also what is the object? I assume you mean GuiObject().
& seems to work exactly as I expect, and yes, guiObject().
The issue is how to have the statement run with differnt flags though.
You can't seem to variablize them, no where to store them, as you can't legally dim something as a tpattachflags.
I have no problem DIMing a tpAttachFlags variable.. you may wish to investigate your script more.
I don't know what you "expect" using "&" to do, but it won't make your code work the way you wish it would. Really, try "+" instead.
Try this script:
<font class="small">Code:</font><hr /><pre>Sub Main()
Dim i As tpAttachFlags
i = tpAttachNoWait & tpAttachChild
TestLog.Comment "combined with &:" & i
i = tpAttachNoWait + tpAttachChild
TestLog.Comment "combined with +:" & i
i = tpAttachNoWait
TestLog.Comment Window("Caption=BogusWindow", i).Exists
TestLog.Comment Window("Caption=BogusWindow", 16).Exists
End Sub</pre><hr />
And you'll gain a good understanding of how the flags work. As you can see, tpAttachFlags is simply an enum of binary numbers.
If you really cannot create a tpAttachFlags variable, then you simply need to pass the integer values of "17" and "16" respectively as your object method's 2nd argument. (this is of course poor programming as it circumvents the advantages of using the tpAttachFlags enum).
I also suggest you change the first line of your function to avoid ambiguity:
public function findAThing(findChildren as boolean) as tGuiObject
The function was simply an example function, the real funtion i'm using it in isn't as ambiguous.
Thanks for the help with the + vs &.
I ended up using tpAttachNoWait + tpAttachChild for both types of searches.
One is searching throughout a window, thus the tpAttachChild doesn't need to be there, but doesn't adversly affect the search, and the other search happens throughout a Frame where the tpAttachChild is needed.