#1 2016-03-27 22:03:53

impulsmedia
Member
Registered: 2015-04-21
Posts: 64

Use vars in Strlen or ArrayIndexOf

Hello,

happy Easter to all! I just fight with a interesting problem. Please have a look at the examples below. Version 1 works as it should, Version 2 returns a -1 although [searchme] has the value "11_HILLER".

ArrayIndexOf "[A_Nachnamen]" "11_HILLER" "result"
ArrayIndexOf "[A_Nachnamen]" "[searchme]" "result"

Same behavior i.e with StrLen.is it not possible to use a var as input?

Thanks,
Walter

Offline

#2 2016-03-27 23:17:43

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Use vars in Strlen or ArrayIndexOf

Hello,

Maybe you found a bug in certain scenario, or maybe the problem is related with some "case sensitive" mistake. The below code works for me, then, try to investigate a little more, for example, assert "[searchme]" must be as is and not "[SearchMe]".

SetVar "[MyVar]" "abcdefghijklmnopqrstuvwxyz" "String"

StrLen "[MyVar]" "[StrLen]"

AlertBox "[StrLen]" "info" // Show 26, just the expected result
NewArray "[MyArray]"
ArrayPush "[MyArray]" "a"
ArrayPush "[MyArray]" "b"
ArrayPush "[MyArray]" "c"

SetVar "[Query]" "b" "String"

ArrayIndexOf "[MyArray]" "[Query]" "[Result]"

AlertBox "[Result]" "info" // Show 1, just the expected result

Offline

#3 2016-03-28 11:44:47

impulsmedia
Member
Registered: 2015-04-21
Posts: 64

Re: Use vars in Strlen or ArrayIndexOf

Hello David, thanks for your answer.
Do you think it could be a problem, because I define var [searchme] in the click of the Select1.SelItems? Means I SetVar "searchme" "[Select1.SelItems]" "String" ? Thanks, Walter

Offline

#4 2016-03-28 11:56:39

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Use vars in Strlen or ArrayIndexOf

Hello Walter,

Yes; certainly could be the problem, maybe SelItems contains more than one item, and, on the other hand, what happend if no items are selected? Anyway may you can test it by place an "Alert" in your code, something like this:

Alert "" "[searchme]"

ArrayIndexOf "[A_Nachnamen]" "[searchme]" "result"

This can be a quick way to look into the "[searchme]" variable contents...

Offline

#5 2016-03-28 13:18:57

impulsmedia
Member
Registered: 2015-04-21
Posts: 64

Re: Use vars in Strlen or ArrayIndexOf

Hello David,

I did the alert test from the begining and the alert always shows me the correct value, i.e 11_HILLER, that is what me drives crazy. I have to leave now, but will send you the app later! Thanks, Walter

Offline

#6 2016-03-28 13:24:27

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Use vars in Strlen or ArrayIndexOf

Hello,

Please, Walter, sorry any inconvenience and, when you can, send me an application in which I can reproduce the problem. Then I will take a look in order to fix it as quickly as possible.

Offline

#7 2016-03-29 08:33:17

impulsmedia
Member
Registered: 2015-04-21
Posts: 64

Re: Use vars in Strlen or ArrayIndexOf

Hello and many thanks to David!

for all others: The solution is simple: The value of a MultiSelect control itsself is an array. This means if you want to search for the result of a single selection in an MultiSelect.Control you have to read first postion of the selected (answer) array:

// example > code in the click event of a MultiSelect.control to read the clicked name and search for it in an second array >>

// this is the result of clicking one item in the MultiSelect. controll Select1
// but because the returned value itself is an array you have to select the first item of the list !!!
ArrayGetItem "[Select1.SelItems]" "0" "[searchme]"

// Now you have a valid string in var [searchme], which you can proof and then make a query to another array
StrLen "[searchme]" "l"
Alert "" "[searchme], length l=[l]"

// search for [searchme in another array in Select2.Items !!!
ArrayIndexOf "[Select2.Items]" "[searchme]" "result"

Offline

#8 2016-03-29 09:15:16

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Use vars in Strlen or ArrayIndexOf

That is the question! smile

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.