String array

Moderator: Moderator Group

String array

Postby matim » Fri Dec 04, 2015 12:15 am

Hello ,

1-is it possible to use StringArray1 in a StringArray2 ?

and access the data like this : Array[1][2]


2 -Is it possible to name the index of a Array like a tuple of key:value ?
ex : Fruit[banana] = 3, Fruit[apple] = 4


Thank you .
matim
 
Posts: 15
Joined: Tue Oct 14, 2014 9:46 am

Re: String array

Postby Yvonne Groetzschel » Tue Dec 08, 2015 4:05 pm

Hello Matim,

I am sorry, but that is not possible in WD. This practice is more like a map, not an array.

Best regards,
Yvonne
Yvonne Groetzschel
 
Posts: 65
Joined: Mon Dec 01, 2014 2:10 pm

Re: String array

Postby matim » Wed Dec 09, 2015 7:08 am

Thank you for the reply.

what do you mean by "map pratice" ?

Mat.
matim
 
Posts: 15
Joined: Tue Oct 14, 2014 9:46 am

Re: String array

Postby Yvonne Groetzschel » Wed Dec 09, 2015 9:18 am

Hello Mat,

a map is an object that maps keys to values. E.g the Java platform contains three general-purpose Map implementations:
HashMap, TreeMap, and LinkedHashMap.
Maps are not supported in WD.

Best regards,
Yvonne
Yvonne Groetzschel
 
Posts: 65
Joined: Mon Dec 01, 2014 2:10 pm

Re: String array

Postby Dennis Kuypers » Wed Dec 09, 2015 9:52 am

Hey,

Array nesting is not yet supported. If you have subarrays of same size then you can create one single array with all items and access them like so (pseudo code):

MyArray[a][b] is then MyArray[a * SUBARRAY_DIMENSION + b]

Dennis
Dennis Kuypers
(former Product Developer, Software)
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: String array

Postby matim » Thu Dec 10, 2015 8:21 am

Thank you Dennis.
i understand the pseudo code. i will use it until WD use the sub array.

another things :

1- i create a string array variable name A
the index 0 have the value <screen id = 2>
if i wrote label1.text = A[0] , the label shows the letter A[0] not my value <screen id =2>

2 -if i have a variable name B with the value 3 by example.
i have to put this value in my array : <screen id = B>
i expect that WD change the B text with the value 3
i need to see <screen id = 3> in my A array but i got <screen id = B>

can you help me

Thank you
Mat.
matim
 
Posts: 15
Joined: Tue Oct 14, 2014 9:46 am

Re: String array

Postby Dennis Kuypers » Thu Dec 10, 2015 1:11 pm

matim wrote:2 -Is it possible to name the index of a Array like a tuple of key:value ?
ex : Fruit[banana] = 3, Fruit[apple] = 4


If you are sneaky then you create integer variables apple=0 and banana=1. Then it works :)

If that is not possible then you can use another workaround that I used before. It requires careful programming.


Fruit[myfruit]
Have two seperate arrays for key and value and keep them in sync:
Fruit_Keys = apple|banana
Fruit_Values = 4|2

Then you can do (again pseudo code)

Code: Select all
index = -1
For 1 to Fruit_Keys.Length:
if Fruit_Keys[for.index] = myfruit
{
 index = for.index
}
Next

If index >= 0
{
# success! my value is Fruid_values[index]
}
else
{
# Not a fruit!
}
Dennis Kuypers
(former Product Developer, Software)
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: String array

Postby Dennis Kuypers » Thu Dec 10, 2015 1:15 pm

matim wrote:if i wrote label1.text = A[0] , the label shows the letter A[0] not my value <screen id =2>


Try the command that does the same, I think it is WDLabelSetText,ID,TEXT.

matim wrote:2 -if i have a variable name B with the value 3 by example.
i have to put this value in my array : <screen id = B>
i expect that WD change the B text with the value 3
i need to see <screen id = 3> in my A array but i got <screen id = B>


This won't work. You have to use something like this to make the replacement:

Sometimes you need to execute dynamically generate code. The 'classic' way to do it is to have a TextBox and use WDTextBoxAppend,ID,TEXT. Then use WDTextBoxexecuteasscript to run it. If you need a comma then you should create a variable named "comma" and then give it the value "," (without quotes).

For example

WDTextboxAppend,1,VSetArrayValue
WDTextboxAppend,1,comma
WDTextboxAppend,1,array_var
WDTextboxAppend,1,comma
WDTextboxAppend,1,screen id =
WDTextboxAppend,1,B # <----- This will be 3 in the textbox, because it is alone. If you put not "B" and use "= B" instead then it wont change B to 3
WDTextboxExecuteAsScript,1
WDTextboxClear,1

Similar is possible using variables instead of the textbox.
Dennis Kuypers
(former Product Developer, Software)
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: String array

Postby matim » Thu Dec 10, 2015 2:35 pm

Dennis,
thank you for the reply.

in your pseudo code about Fruit , the next should be at the end of code ?

sorry, i wrote something wrong about A[0] , it works with the label1.text command.
it won't work within a function and argument.
i think because of the variable's scope. ( global or local )
i have to put the argument in a temp array in my function to process the value.

ok i understand the concept of execute text as script
do you miss the index of array in this example ?

Mat.
matim
 
Posts: 15
Joined: Tue Oct 14, 2014 9:46 am

Re: String array

Postby Dennis Kuypers » Thu Dec 10, 2015 9:47 pm

matim wrote:in your pseudo code about Fruit , the next should be at the end of code ?

No. The For-Next is only to find out the position of the key in the key array. The Keys and Values are in two different arrays. If you can find the Key in the Key array, then then corresponding value is in the Values array (at the same position). the problem is that when adding values to the Values array you also have to add the key to the Keys array. Keeping Keys and Values in sync is sometimes not trivial. You can not do sorting, or you mess up the relationship between them.

Another Idea: Only have one array, but store key and value with a seperator. You can then use the split function to split up key and value. Looking up a key also requires a For-Next loop.


matim wrote:it won't work within a function and argument.
i think because of the variable's scope. ( global or local )

There is no scope in Widget Designer (well, the arguments in functions are scoped somewhat). Note that functions basically work by replacing argument occurrences with the given values.

matim wrote:do you miss the index of array in this example ?

Yes i forgot about the index.
Dennis Kuypers
(former Product Developer, Software)
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm


Return to Widget Designer V4.7

Who is online

Users browsing this forum: No registered users and 11 guests

cron