Invalid Variant Operation error - delphi

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?

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.

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.

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.

Related

Unable to properly loop through keys AND values in a VB6 For Each loop

I'm making a program in VB6, and I can't properly loop through a String dictionary.
I've tried both ways of accesssing a value in the collection. Collection(Key), and Collection.Item(Key).
Dim line As Variant
Dim thismsg As New Collection
Dim thissection As String
For Each line In Split(NetRcv, vbLf)
If Left(line, 3) = "BLK" Then
thissection = Right(line, Len(line) - 3)
MsgBox thissection
GoTo nctlrParseLoopNext
End If
If Left(line, 3) = "BND" Then
Exit For
End If
Dim key, value As String
key = Left(line, InStr(line, " "))
value = Right(line, InStr(line, " "))
thismsg.Add key, value
nctlrParseLoopNext:
Next line
Dim member As Variant
For Each member In thismsg
MsgBox member
MsgBox thismsg(member)
Next member
The string in NetRcv is the following:
BLK modeswitch
mode codeslave
BND
I expect to see this sequence of MsgBoxes ...
modeswitch
mode
codeslave
... with possibly trailing spaces somewhere.
I see the first two, and then it errors with
Run-time error '5':
Invalid procedure call or argument
I don't understand why this error occurs.
member is the key, correct?
If it is, then there's no reason this error should pop up.
For one thing, you have inverted the value and key. This:
thismsg.Add key, value
should be this:
thismsg.Add value, key
See here for the docos on the Add method
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/add-method-visual-basic-for-applications

Value stored in a variable is different than what is returned by the right hand side of '='

If I execute
env['rack.request.cookie_string'].split('\; ')
I get the expected result (array of strings). I have a line of code like this in my controller action:
foo = env['rack.request.cookie_string'].split('\; ')
When I stop with byebug just after that line, foo contains the entire cookie string env['rack.request.cookie_string']. What is going on?
Problem solved. I had to use split("\; ") instead of split('\; ').

Cannot access params map using Groovy

I want little help which I suspect is due to my lack of understanding for Groovy syntax. So, here's the thing:
On the GSP page I want to set a field's value from the params map which is
["id":"107901", "Field_10.value":"2", "Field_10":["value":"2"],"Field_11.value":"", "Field_11":["value":""],action:'abc']
On the gsp page, I want to find the value against the key Field_{some-id}.value
So I am calling a tag like, g.testTag(id:field.id) with its implementation as
def testTag = { attrs,body->
println "params are ${params}"
def result = ""
def keyRequired = "Field_${attrs.id}.value"
println "keyRequired >>>>> ${keyRequired.toString()}"
params.each { key,value->
println "key is ${key}"
println "Value is ${value}"
if (key.equals(keyRequired.toString())) {
result = params.value
}
}
println "Final result is >>>>>> ${result}"
}
The value passed in id is 10 and with my params printed as above, I was expecting a value
of 2 which is corresponding to the key in the params to show up. But apparently I see the
result as null..
What am I doing wrong ? Can anyone help please...
Thanks
Not result = params.value, but result = value.
You have to change the line:
result = params.value
to:
result = value
At the each loop, you're basically saying that inside the params iteration, you're naming every key "key" and every value "value". So, params.value will actually look for the key value inside your params map, which is null.
Funny that you do that right with key but not with value. Probably just got distracted.
it is likely what you want to do, the groovy way (no need to loop over the keys of the map) to access "Field_10.value":"2"
result=params["Field_${attrs.id}.value"]
Alternatively, this also works because you have "Field_10":["value":"2"] in your map
result=params["Field_${attrs.id}"].value

Simplexml (invalid argument supplied foreach)

ERROR= Warning: Invalid argument supplied for foreach() in [path]/deals2.php on line 168
The XML: http://www.freeimagehosting.net/2sjdd
No idea what i'm doing wrong. Never ran into this issue before.
$xml = simplexml_load_file('http://api.yipit.com/v1/deals/?key=mykey&division=houston&format=xml');
foreach($xml->deals->list-item as $shortcut)
{
$title = $shortcut->{'title'};
echo $title;
}
There are no "deals" element name in your xml
Every element name that has a dash symbol '-' must be escaped with {'some-element'} so even if list-item element would exist (it does not) you would need to escape it. http://www.kombitz.com/2010/02/10/php-xml-problem-hyphen-in-the-element-name/
I modified your code to
foreach($xml->meta->code as $a) { echo $a; }
And it worked fine. Try my advice above and try using elements that actually exist.
And by the way, your XML is not even properly structured. What is that
<response/>
doing there?? A lot of errors. :)

" '}' expected near '=' " error appearing in a line that otherwise appears perfect

When I attempt to run my script, I get an error returning on a variable assignment. I've re-checked my syntax many times and it doesn't seem to be a mistake I made there--I even had somebody else look at it just in case. However, the error that returns continuously points me to the syntax, and I can't seem to find a solution to this problem.
Here is the whole troublesome function:
function registerquestlines()
if player["testline"] == nil then
player["testline"] = {"prog" = {true,false,false}, "quests" = {"testline1", "testline2", "testline3"}, "prog#" = 1}
end
end
Again, the error I get is: '}' expected near '=' on the line in which I assign values to player["testline"].
A table initializer uses either an unquoted name or a bracketed expression, not a quoted name.
{prog = {true,false,false}}
{["prog"] = {true,false,false}}

Resources