Well, you're not implementing our sample code properly.
You shouldn't re-enable the control when one item in the loop doesn't match the ID to test simply because you won't have
all used IDs matching that one ID, you have to check whether there is
at least one match.
js code:
if (isNaN (objWnd.GetControlText("EdtLeft") * 1) == true || isNaN (objWnd.GetControlText("EdtDown") * 1) == true || isNaN (objWnd.GetControlText("EdtWidth") * 1) == true || isNaN (objWnd.GetControlText("EdtHeight")) == true)
{
Interop.Call("user32", "EnableWindow", objWnd.GetControlHandle("BtnAdd"), 0);
}
else
{
>>> var bCanChange = true;<<<
>>> var sEdtId = objWnd.GetControlText("EdtId");<<<
for (var X in WndLstId)
{
>>> if (WndLstId.length > 1 && sEdtId == WndLstId[X] && X == WndLstTStSel)<<<
{
>>> bCanChange = false;<<<
>>> break;<<<
}
}
}
>>> Interop.Call("user32", "EnableWindow", objWnd.GetControlHandle("BtnChange"), bCanChange);<<<
}
As you can see, you don't need an else-block anywhere, you simply check three things:
- Check whether there are IDs in the array.
- Check whether the currently chosen test ID matches the key name of the current item in the loop.
- Check whether this item is currently being edited.
When these three conditions are fulfilled for one item in the loop, we can say that the chosen ID is not unique and thus bCanChange has to be set to false in order to disable the edit button.
When these conditions are never fulfilled, bCanChange will never change from its original value (true) and the button will be enabled.
Oh, on a side note: try to store some of the GetControlText calls in a variable inside your functions when you use them very often. It's good practice to take off the load of the API to get the control text every time and simply retrieve the value from a variable - the control text won't change anyway while executing the event function (and you don't want it to change either).