Report Bugs Here

Moderator: Mmiscool

User avatar
By livetv
#54933 This is bizarre! I'm setting up arrays, parsing string values into these arrays (why I do this is another matter) but when I recall values from these arrays, they are way wrong!

Code: Select alllet dev_name="temp1 temp2 temp3 temp4 temp5 temp6 flood pump pswitch power lowp"
let dev_type_str="88888875155"
let dev_pin_str= "0 1 2 3 4 5 6 3 4 5 12"
dim dev_value(20)
dim dev_new_val(20)
dim dev_pin(20)
dim dev_type(20)
for t=1 to len(dev_type_str)
    let temps= mid(dev_type,t,1)
    let dev_type(t)=val(temps)
    let temps=word(dev_pin_str,t)
    let dev_pin(t)=val(temps)
    next t

' Now recall and report from arrays
cls
for t=1 to len(dev_type_str)
    wprint dev_type(t)
    wprint " "
    wprint dev_pin(t)
    wprint "<br>"
    next t
wait


So I worked on this, adding WPRINT statements to the initialization loop to find problems there too. Seems that V=VAL(TEMPS) throws an error but changing TEMPS to TEMP$ does work. That looks like a whole different bug. But changing the code to isolate the problem to array write/read gives me the following code which still does not work:

Code: Select alllet dev_name="temp1 temp2 temp3 temp4 temp5 temp6 flood pump pswitch power lowp"
let dev_type_str="88888875155"
let dev_pin_str= "0 1 2 3 4 5 6 3 4 5 12"
dim dev_value(20)
dim dev_new_val(20)
dim dev_pin(20)
dim dev_type(20)
cls
wprint "Assing values to arrays...<br>"
for t=1 to len(dev_type_str)
    let temp$= mid(dev_type_str,t,1)
    let v=val(temp$)
    wprint v
    wprint " - "
    let dev_type(t)=v
    let temp$=word(dev_pin_str,t)
    let v=val(temp$)
    wprint v
    wprint "<br>"
    let dev_pin(t)=v
    next t
wprint "<br>Recalling values...<br>"
for t=1 to len(dev_type_str)
    wprint dev_type(t)
    wprint " - "
    wprint dev_pin(t)
    wprint "<br>"
    next t
wait


My recalled values are:

70975523162658884501752.25443 - 0
0 - 0
0 - 0
0 - 0
0 - 0
0 - 0
293882386519807514702051776112.05726 - 0
72053216539090128023303.80509 - 0
0 - 0
293882386519807514702051776112.05726 - 0
1112820201451986124041582115.75122 - 0

Uhm... I'm stumped.
User avatar
By bugs
#54947 This version seems to give the expected result:--
Assing values to arrays...
8 - 0
8 - 1
8 - 2
8 - 3
8 - 4
8 - 5
7 - 6
5 - 3
1 - 4
5 - 5
5 - 12

Recalling values...
8 - 0
8 - 1
8 - 2
8 - 3
8 - 4
8 - 5
7 - 6
5 - 3
1 - 4
5 - 5
5 - 12

Code: Select alllet dev_name="temp1 temp2 temp3 temp4 temp5 temp6 flood pump pswitch power lowp"
let dev_type_str="88888875155"
let dev_pin_str= "0 1 2 3 4 5 6 3 4 5 12"
dim dev_value(20)
dim dev_new_val(20)
dim devpin(20)
dim dev_type(20)
cls
wprint "Assing values to arrays...<br>"
for t=1 to len(dev_type_str)
    let temp$= mid(dev_type_str,t,1)
    let v =val(temp$)
    wprint v
    wprint " - "
    let dev_type(t) = v
    let temp$=word(dev_pin_str,t)
    let v = val(temp$)
    wprint v
    wprint "<br>"
    let devpin(t) = v
    next t
wprint "<br>Recalling values...<br>"
for t=1 to len(dev_type_str)
    wprint dev_type(t)
    wprint " - "
    wprint devpin(t)
    wprint "<br>"
    next t
wait


I experimented with your array names and $ and removing the superfluous "lets" without success.
The problem seems to be that the parser still wants spaces on some lines i.e around the "=" sign.
I do not have time to experiment any more to narrow it down - so good luck.
:|
User avatar
By Mmiscool
#54958 When creating an array you must define wether it is a string or a value.

You can do this one of 2 ways.

If you use the dim command and the array name dose not end in a $ it will assume the array to be numeric. If you add the $ to the end of the array name it will assume string as the type.

You can also add the "as string" to the end of the dim command to define an array with out the $ sign as a string.

Code: Select allDim bla(5) as string
User avatar
By livetv
#54970 @mmiscool: I am not using string typed arrays. You'll see that I convert string values to numeric values before making my assignments to the arrays. Always good info though!

@bugs: I copied the code you posted and got the same erroneous results I was getting before.

After a lot of fooling around I isolated the problem to assignment of values to the array and testing shows that using LET in the assignment causes the problem whereas omitting it gives correct results. So that's the bug.