Morgan
11 years agoFrequent Contributor
Incrementing an action
I'm trying to create a little script that loops through a dropdown to find the desired value. Can someone direct me as to an example? Thanks, Morgan
Initial code looks as follows.... what's not working is that the [Down] needs to increment each time. So first time, one down action is needed, second 2, etc...
Thanks!
Morgan
----
repeat // If X appears in the list, we select it and continue.
grdAnalyte.Keys(' ');
grdAnalyte.Keys('[Down][Enter]');
Delay(Std_Wait);
until frmAnalyte.Window('TDBGridInplaceEdit', '', 1).text = 'X';
you could put the call to [Down] in a loop and increment the times that loop is executed each time it is called.
in pseudo code:
maxLoop = 0
repeat // If X appears in the list, we select it and continue.
maxLoop++
grdAnalyte.Keys(' ');
for (i=0; i < maxLoop; i++) {
grdAnalyte.Keys('[Down][Enter]');
}
Delay(Std_Wait);
Hmmm... I think I get what you are saying but I'm having trouble converting it to DelphiScript. Any ideas?
Appreciate the help!
Morgan
Hi - I can't help with Delphi (sorry).
Here is something in JScript which might be helpful? I wasn't sure what you were trying to do - this just selects a desired drop down using Keys to find the one you want - I actually have trouble sometimes using ClickItem function so sometimes use the Keys function:
function selectDropDown(theDropDown, valueToSelect) {
Log.Message("About to select the value " + valueToSelect + " from the drop down");
Delay(2000);
Aliases.RefreshMappingInfo();
theDropDown.WaitProperty("Exists", true, 10000);
theDropDown.scrollIntoView(false);//the false is important!
var theList = theDropDown.wItemList;
Log.Message(theList);
var currentIndex = theDropDown.selectedIndex;
var indexToClick = findItemIndex(theList, valueToSelect, SEMI_COLON);
var clicksNeeded = indexToClick - currentIndex;
if (clicksNeeded == 0) {
return;
} else if (clicksNeeded > 0) {
for (var i = 0; i < clicksNeeded; i++) {
theDropDown.Keys("[Down]");
}
} else {
for (var i = 0; i < clicksNeeded; i++) {
theDropDown.Keys("[Up]");
}
}
var currentIndex = theDropDown.selectedIndex;
}
Hurray! I figured it out! Your post, Tony, reminded me that I might try to instead see if I had access to the ItemIndex for the selected value. Which I did. That makes life MUCH easier. It's these silly dropdowns nested within grids that were causing issues... this simplifies it to just a couple of lines of code to confirm that the selected value is correct (versus iterating through with Sys.Keys which was only working cleanly on some OS's the scripts were running on).
Thanks for brainstorming with me - that was helpful!