action script 2.0 simple string comparing with conditional statement - actionscript

So I have this crazy problem with comparing 2 strings in ActionScript 2.0
I have a global variable which holds some text (usually it is "statistic") from xml feed
_root.var_name = fields.firstChild.attributes.value;
when I trace() it it gives me the expected message
trace(_root.var_name); // echoes "statistik"
and when I try to use it in conditional statement the rest of code is not being executed because comparing :
if(_root.overskrift == "statistik"){
//do stuff
}
returns false!
I tried also with:
if(_root.overskrift.equals("statistik"))
but with the same result.
Any input will be appreciated.

Years later but on a legacy project I had the same problem and the solution was in a comment to this unanswered question. So let's make it an anwer:
Where var a:String="some harmless but in my case long string" and var b:String="some harmless but in my case long string" but (a==b) -> false the following works just fine: (a.indexOf(b)>=0) -> true. If the String were not found indexOf would give -1. Why the actual string comparison fails I coudn't figure out either. AS2 is ancient and almost obsolete...

Related

Array.size() returned wrong values (Grails)

I'm developing an app using Grails. I want to get length of array.
I got a wrong value. Here is my code,
def Medias = params.medias
println params.medias // I got [37, 40]
println params.medias.size() // I got 7 but it should be 2
What I did wrong ?
Thanks for help.
What is params.medias (where is it being set)?
If Grials is treating it as a string, then using size() will return the length of the string, rather than an array.
Does:
println params.medias.length
also return 7?
You can check what Grails thinks an object is by using the assert keyword.
If it is indeed a string, you can try the following code to convert it into an array:
def mediasArray = Eval.me(params.medias)
println mediasArray.size()
The downside of this is that Eval presents the possibility of unwanted code execution if the params.medias is provided by an end user, or can be maliciously modified outside of your compiled code.
A good snippet on the "evil (or lack thereof) of eval" is here if you're interested (not mine):
https://javascriptweblog.wordpress.com/2010/04/19/how-evil-is-eval/
I think 7 is result of length of the string : "[37,40]"
Seems your media variable is an array not a collection
Try : params.medias.length
Thanks to everyone. I've found my mistake
First of all, I sent an array from client and my params.medias returned null,so I converted it to string but it is a wrong way.
Finally, I sent and array from client as array and in the grails, I got a params by
params."medias[]"
List medias = params.list('medias')
Documentation: http://grails.github.io/grails-doc/latest/guide/single.html#typeConverters

Report Code (.frf file)

in the below code I would like to change the final IF NOT statement to say either HEADING or SPACE. I have tried to play around with it (I did not write this code) without success. Sorry am not an expert not sure what code it is in! Any ideas? Thanks
if [POS('HEADING',[DF.Items."CODE"])] then MemoLRV.visible:=false;
if [POS('SPACE',[DF.Items."CODE"])] then MemoLRV.visible:=false;
if [POS('HEADING',[DF.Items."CODE"])] then MemonameV.font.Color:=clmaroon;
if not [POS('HEADING',[DF.Items."CODE"])] then MemonameV.font.Color:=clblack;
if not [POS('HEADING',[DF.Items."CODE"])] then MemoLRV.visible:=true;
In FastReport function IF :
IF(Expression, Value1, Value2)
Returns Value1 if expression Expression is True, otherwise returns Value2. Return value can be not only string.

LoadRunner web_reg_save_param, ord=all, paramName_count issues

I am using LoadRunner version 12.02 - Build 2739
Looking at an old, yet correct 'guide' shows that I have used the statements correctly (3rd Point, around 1/3rd of the way down the page, inside the code block - the atoi statement).
But I am still unable to convert the _count parameter to an int-Variable.
In the script, before the call is made;
web_reg_save_param(
"ParamName=rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
After the web call the save_param function is placed before, the output log shows;
Notify: Saving Parameter "ParamName=rotaPeople_count = 21".
Inside the script, after the call is made, and the count has been totaled;
lr_output_message("RP_C:%d",lr_eval_string("{rotaPeople_count}"));
lr_output_message("RP_C:%s",lr_eval_string("{rotaPeople_count}"));
peoplesCount = atoi(lr_eval_string("{rotaPeople_count}"));
lr_output_message("PC:%d",peoplesCount);
In the logs after the above executions are made;
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
RP_C:110826864
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
RP_C:{rotaPeople_count}
Warning: The string 'rotaPeople_count' with parameter delimiters is not a parameter.
PC:0
Anyone have any ideas?
Note: The Warning messages are expected
Note: Workaround: Used web_reg_save_param_regex() and created a regular expression. Using the returned _count parameter within a for-loop worked. Keeping question open, as the original problem still persists
The problem is that you use a soon to be deprecated API web_reg_save_param which does not support the ParamName syntax. In this API the second parameter is always the parameter name and therefore the correct use would be:
web_reg_save_param(
"rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
The proper API to use is web_reg_save_param_ex which does support the syntax you used so the call should look like:
web_reg_save_param_ex(
"ParamName=rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
Then the rest of your code should work properly.
I am not sure what you are doing but you might want to take a look at the somewhat unknown API lr_paramarr_random which will automatically pull a random value from the parameters array.
This should help you
web_reg_save_param(
"rotaPeople",
"LB=someText",
"RB=\")",
"Ord=ALL",
LAST);
lr_output_message("PC:%d",atoi(lr_eval_string("{rotaPeople_count}")));
You are using ord=all,see the run time data which value you want to capture,If you want to capture the 10th value please use ord=10,automatically this warning will remove from output log.
Example for capturing an array of dynamic values:
Action()
{
int i;
int ncount;
char ParamName[100];
web_set_sockets_option("SSL_VERSION", "TLS");
web_reg_save_param("trackingno","LB=;","RB= (NTN 0430)","search=All","ord=all",LAST);
web_submit_data("barcode.pl",
"Action=http://qtetools.rmtc.fedex.com/barcode/cgi-bin/barcode.pl",
"Method=POST",
"TargetFrame=",
"RecContentType=text/html",
"Referer=http://qtetools.rmtc.fedex.com/barcode/html/barcode.shtml",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=formcode", "Value=0430", ENDITEM,
"Name=count", "Value=10", ENDITEM,
"Name=narrow", "Value=2", ENDITEM,
LAST);
ncount= atoi(lr_eval_string("{trackingno_count}"));
for (i =1;i <= ncount;i++)
{
sprintf(ParamName, "{trackingno_%d}", i);
lr_output_message("Value of %s: %s",ParamName,lr_eval_string(ParamName));
}
return 0;
}

Python parsing error message functions

The code below was created by me with the help of many SO veterans:
The code takes an entered math expression and splits it into operators and operands for later use. I have created two functions, the parsing function that splits, and the error function. I am having problems with the error function because it won't display my error messages and I feel the function is being ignored when the code runs. An error should print if an expression such as this is entered: 3//3+4,etc. where there are two operators together, or there are more than two operators in the expression overall, but the error messages dont print. My code is below:
def errors():
numExtrapolation,opExtrapolation=parse(expression)
if (len(numExtrapolation) == 3) and (len(opExtrapolation) !=2):
print("Bad1")
if (len(numExtrapolation) ==2) and (len(opExtrapolation) !=1):
print("Bad2")
def parse(expression):
operators= set("*/+-")
opExtrapolate= []
numExtrapolate= []
buff=[]
for i in expression:
if i in operators:
numExtrapolate.append(''.join(buff))
buff= []
opExtrapolate.append(i)
opExtrapolation=opExtrapolate
else:
buff.append(i)
numExtrapolate.append(''.join(buff))
numExtrapolation=numExtrapolate
#just some debugging print statements
print(numExtrapolation)
print("z:", len(opExtrapolation))
return numExtrapolation, opExtrapolation
errors()
Any help would be appreciated. Please don't introduce new code that is any more advanced than the code already here. I am looking for a solution to my problem... not large new code segments. Thanks.
The errors() function is called after parse() returns because it appears inside the body of parse(). Hopefully that is a typo.
For this particular input, numExtrapolate is appended with an empty buffer because there is no operand between / and /. That makes its length 4 and your check for Bad1 fails. So put a check like this
if buff:
numExtrapolate.append(''.join(buff))

Lua arguments passed to function in table are nil

I'm trying to get a handle on how OOP is done in Lua, and I thought I had a simple way to do it but it isn't working and I'm just not seeing the reason. Here's what I'm trying:
Person = { };
function Person:newPerson(inName)
print(inName);
p = { };
p.myName = inName;
function p:sayHello()
print ("Hello, my name is " .. self.myName);
end
return p;
end
Frank = Person.newPerson("Frank");
Frank:sayHello();
FYI, I'm working with the Corona SDK, although I am assuming that doesn't make a difference (except that's where print() comes from I believe). In any case, the part that's killing me is that inName is nil as reported by print(inName)... therefore, myName is obviously set to nil so calls to sayHello() fail (although they work fine if I hardcode a value for myName, which leads me to think the basic structure I'm trying is sound, but I've got to be missing something simple). It looks, as far as I can tell, like the value of inName is not being set when newPerson() is called, but I can't for the life of me figure out why; I don't see why it's not just like any other function call.
Any help would be appreciated. Thanks!
Remember that this:
function Person:newPerson(inName)
Is equivalent to this:
function Person.newPerson(self, inName)
Therefore, when you do this:
Person.newPerson("Frank");
You are passing one parameter to a function that expects two. You probably don't want newPerson to be created with :.
Try
Frank = Person:newPerson("Frank");

Resources