Report Bugs Here

Moderator: Mmiscool

User avatar
By bugs
#54973 Strange - I have just copied that code (from my last post) and pasted and run it and it gives the correct answer. I am using version 3.0 alpha 45 if that makes any difference.
But I have been suspicious about "lets" recently which is why I tried removing then from your original code.
User avatar
By Oldbod
#54975 I have found in the past (don't know if this is still so, or recall which ver i was using) that
'let n=1' or 'n =1' works but 'n=1' doesn't. so there have been some idiosyncracies with let, but...

I think the point mmiscool was making is that you are using this code

dim dev_type(20) >>>> create an array of numeric values, not strings
for t=1 to len(dev_type_str)
let temps= mid(dev_type,t,1)

when you dim'd the dev_type, you created a numeric array.
then you "let temps= mid(dev_type,t,1)"

so you're using a string operator ("mid") on a numeric value with no array index. Which I would expect to either give an error or cause a new, single element variable to be created called "dev_type" if espbasic differentiates between arrays and single variables of the same name. I'd urge, though espbasic doesnt require it, that you use a $ as part of the variable name for readability purposes....and also stick spaces either side of the '=' j.i.c...

Did you mean perhaps "let temps= mid(dev_type_str,t,1)"

It's all too easy to read and read and read code you've written and see what you know should be there, not what IS there. Lost count (hundreds, maybe thousands) of the number of times I've run through my code explaining it, or had someone else explain their code to me, and found something like that.
User avatar
By bugs
#55017 There is a moving target somewhere.
I just switched on and pasted precisely that same code that was working yesterday and it produced the error results until I removed every single "let" from the code.
I have suspected "let" in the past because it has shown up in the Vars table - sometimes e.g if the code was let n=1 then Vars showed let n = 1 instead of n = 1.
Sometimes...
User avatar
By Mmiscool
#55019 It seem that there is a bug when asiging a variable a value using the let command.

If you omit all of the let commands it will work as intended.

The let command is only screwing up assignment of a value to an array' element. Not any other usage of an array.

Also be sure to use spaces around the = sign for the assignment of a variable.

ie.
good:
bla = 1

bad:
bla=1
bla =1
bla= 1

Code: Select allmemclear
t = 0
dev_name = "temp1 temp2 temp3 temp4 temp5 temp6 flood pump pswitch power lowp"
dev_type_str = "88888875155"
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)
    temp$ = mid(dev_type_str,t,1)
    v = val(temp$)
    wprint v
    wprint " - "
    dev_type(t) = v
    temp$ = word(dev_pin_str,t)
    v = val(temp$)
    wprint v
    wprint "<br>"
    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