Forum Discussion

joetesta's avatar
joetesta
Roku Guru
13 years ago

help debugging Invalid value for left-side of expression

Hello,

I'm trying to set up custom search history as described by RokuJoel here: viewtopic.php?f=34&t=49729&p=339297&hilit=roSearchHistory#p339297

However after the history is set, I'm seeing an error and my app is crashing:
Invalid value for left-side of expression. (runtime error &he4) in ...g:/source/appSearchScreen.brs(337)

337: m.titlehistorylist[j]=histemp[i]


Apparently the roku doesn't like that I'm trying to set m.titlehistorylist with an index (even when j = 0), but I'm not sure why or what's different that prevented this problem in the example. As a workaround, I'm using
m.titlehistorylist=histemp
but I presume this is reversing the desired order...

Can anyone give me a clue what's going wrong, why does the example work (or does it?) but this doesn't?
tyvmia
  • What are the values of histemp and m.titlehistorylist?

    in the second example it appears you are assigning the whole histemp array to m.titlehistorylist which is essentially making m.titlehistorylist a pointer to histemp, if histemp is an array.

    - Joel
  • Hi RokuJoel,
    i and j are both 0, histemp[0] should be the first (& only, in this case) stored value in the registry. m.titlehistorylist should be unassigned. Here's the function that's failing:

    function loadsearchHistory() 
    if not checkreg("history","search_title_hist") then
    ?"no title search history in the registry"
    createregsection("history","search_title_hist", "")
    m.titlehistorylist=""
    else
    ?"found title search history, loading"
    histemp=box(readreg("history","search_title_hist").tokenize(","))
    i=histemp.count()-1
    j=0
    while true
    if i=-1 or j > histemp.count() -1
    exit while
    end if
    m.titlehistorylist[j]=histemp[i]
    'm.titlehistorylist=histemp
    i=i-1
    j=j+1
    end while
    end if
    end function


    And here's how I was putting the list in registry, based on viewtopic.php?f=34&t=49729&p=339297&hilit=roSearchHistory#p339297 and using the identical "arraytostring" function you posted there.
    function update_title_history(histlist As Object, querystring As String) As Dynamic
    flag=0
    ? "histlist = " Type(histlist)
    ? "querystring = " Type(querystring)

    if islist(histlist) = false
    ? "setting histlist[0] to " querystring
    histlist = CreateObject("roArray",1,1)
    histlist[0] = querystring
    else
    ? "looping over title history now"
    for i=0 to histlist.count()-1
    if querystring=histlist[i]
    flag=1
    end if
    next i

    if flag <> 1 then
    histlist.unshift(querystring)
    if histlist.count() > 9
    histlist.pop()
    end if
    end if
    end if

    m.titlehistorylist=histlist
    writereg("history","search_title_hist",arraytostring(histlist))
    return histlist
    end function


    I noticed without this code that the list is reversing order each time the search screen is called, and then when there are more than 9 stored entries, it's keeping rather than discarding the oldest entries over newer ones.

    thanks a lot for any help,
    joe
  • I could not figure out why that error happens, so I found a work-around. Now I am creating a temporary array to hold the reversed history and then I assign it to m.titlehistorylist after looping over the elements, like this:

    function loadsearchHistory() 
    if not checkreg("history","search_title_hist") then
    ?"no title search history in the registry"
    createregsection("history","search_title_hist", "")
    m.titlehistorylist=CreateObject("roArray", 1, true)
    else
    ?"found title search history, loading"
    histemp=box(readreg("history","search_title_hist").tokenize(","))
    temp1=CreateObject("roArray", 1, true)
    i=histemp.count()-1
    j=0
    while true
    if i=-1 or j > histemp.count() -1
    exit while
    end if
    'm.titlehistorylist[j]=histemp[i]
    temp1[j]=histemp[i]
    i=i-1
    j=j+1
    end while
    m.titlehistorylist=temp1
    end if
    end function


    now it's working, although i still wish I understood why the error happens when trying to assign values to the m.titlehistorylist array...
  • I figured out if I just declare
    m.titlehistorylist =CreateObject("roArray", 1, true)
    before entering the loop, then it works as expected. I thought that 'm.titlehistorylist' was already array at this point in the app, but apparently not.