skip to Main Content
m.CurrDateObject = FindCurrDateObject(m.itemContent.date)
?"title :"m.CurrDateObject.title //Here I got Type Mismatch Error When 0 comes
?"text :"m.CurrDateobject.text

‘FindCurrDateObject Return Object when if condition true in function
‘when if condition false then it’s return 0
‘Here, I received two different data types on the function

  1. If Condition true => Object
  2. If Condition false => 0 as Integer

Can anyone suggest How can I manage this two data types on Roku?

function FindCurrDateObject(date as Integer) as Object
    m.date = CreateObject("roDateTime")
    m.myObject = {}
    for each item in m.global.itemArray
        now = m.date.AsSeconds()
                if (now >= date) then
                            m.myObject.title = item.title
                            m.myObject.text = item.text
                            return m.myObject 
                 //This below-mentioned part works, but it's called every time. I don't want to return the invalid value
                 'else 
                 'return invalid                      
             end if
    end for
end function

2

Answers


  1. The function FindCurrDateObject can be improved like this-

    function FindCurrDateObject(date as Integer) as Object
        date = CreateObject("roDateTime")
        myObject = {}
        now = m.date.AsSeconds()
        for each item in m.global.itemArray
            if (now >= date)
                myObject.title = item.title
                myObject.text = item.text
                exit for
            end if 
        end for
        return myObject
    end function
    
    Login or Signup to reply.
  2. function FindCurrDateObject(dateAsSeconds as Integer) as Object
        dateTimeObj = CreateObject("roDateTime")
        timeNowAsSeconds = dateTimeObj.AsSeconds()
        m.myObject = {}
        for each item in m.global.itemArray
            if (timeNowAsSeconds >= dateAsSeconds) then
                m.myObject.title = item.title
                m.myObject.text = item.text
                return m.myObject 
            else 
                return Box(0) // This will return roInteger object                     
            end if
        end for
    end function
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search