- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Type Mismatch Object and Integer
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
- If Condition true => Object
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Type Mismatch Object and Integer
If you want to return an Object sometimes and an Integer others, you have to make the return type of the function "Dynamic":
function FindCurrDateObject(date as Integer) as Dynamic
This can lead to other problems because you can't just test to see if it returns 0. For example:
if FindCurrDateObject(date) = 0 then
' do whatever
end if
This will throw an error if FindCurrDateObject returns an object. Likewise if it does return 0 then you'll get the error you're seeing when you try to access the returned value as an object (i.e., ?CurrDateObject.text)
To be honest, returning "invalid" is probably the better way to go since you can always test for a return of invalid.
There's probably other ways to accomplish whatever it is that you're trying to do like returning empty strings for title and text instead of 0 or invalid.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.