Reputation:
I have an error in my button click, and I can't figure out how to resolve it.
This is my code:
if (ovElements.item(i).name = 'add') and
(ovElements.item(i).type = 'button') and
(ovElements.item(i).Value = ' + ') then
ovElements.item(i).Click;
This is the markup:
<td width="20" align="left"><input class="button" style="width: 30px;"
name="add" value=" + " onclick="addLvl();" type="button"></td>
And it gives this error:
Invalid Variant Operation Error
What did I do wrong?
Upvotes: 1
Views: 16981
Reputation: 43595
It means an operation on a variant which is executed is invalid. This happens, for example, when a variant containing some text is divided by an integer. Clearly this cannot work, but since the compiler can't check this, it is a runtime error.
Use a temporary variable for the 3 parts in your if statement to see better on which line the error is raised. Then inspect what the values are and what the invalid operation is.
Upvotes: 1
Reputation: 8241
You can save "ovElements.item(i)" to a local variable and then split your code into multiple line.
obj = ovElements.item(i);
if obj <> nil then
try
if obj.name = 'add' then
if obj.type = 'button' then
if obj.value = ' + ' then
obj.click;
except
end;
In this way you can see which line causes this problem.
Upvotes: 1
Reputation: 3717
Just a guess:
ovElements.item(i).Value is probably a Variant. If a variant contains a null value you will get that error when you compare it to a string.
Make sure ovElements.item(i) doesn't contain a null value before comparing it.
Upvotes: 1