Put variable into field "field"
Posted: Wed Aug 21, 2013 3:06 am
Hey everyone
So, I've been adding features to my app and all that, and have come across a problem. Since the app is showing a list of events that are coming up (which is read from a dropbox link), I want to make it so that if the user isn't connected to the internet, it will still show the latest version of the events that is was able to download. Here's the code I've got so far:
(this part is on the splashscreen)
put false into connected
put false into offline
put "Keep trying" & return & "Offline mode" & return & "Exit" into conoptions
repeat while connected is false
put url ("http://www.google.com?timestamp="& the milliseconds) into testurl
if testurl is empty then
mobilepick conoptions
if the result=1 then
put false into connected -- keeps trying to connect to internet
else if the result=2 then
put true into connected
put true into offline -- offline mode
else if the result=3 then
quit -- exit
end if
else
put true into connected
end if
end repeat
This bit works perfectly. This next bit is on the main card:
if offline is false then -- get dropbox version of file
put specialfolderpath("Documents") & "/Events.lc" into eventsdl
if leader=true then
put url "Leader Dropbox link" into events
else
put url "Dropbox link" into events
end if
put events into url ("file:" & eventsdl)
else if offline is true then -- get previous version of file if there is one
put specialfolderpath("Documents") & "/Events.lc" into eventspath
if there is a file eventspath then
open file eventspath for read
read from file eventspath until eof
put it into events
close file eventspath
else
answer "Sorry, you haven't opened the app before! You need to download the events at least once to display it!"
put empty into events
end if
end if
put events into field "events"
Now, it all seems to work well - I can put answer {variable} where needed and it will all show up. So, answer events shows a messagebox with events, answer offline shows the status of offline etc. The issue is the last line, put events into field "events". For some reason, the code works when it's connected to internet, but when it's not, it doesn't put events into field "events". I even had a bunch of answer lines in thee to see where it was up to, like this:
else if offline is true then
put specialfolderpath("Documents") & "/Events.lc" into eventspath
if there is a file eventspath then
answer "There's a file!"
open file eventspath for read
read from file eventspath until eof
put it into events
close file eventspath
answer events
end if
else
answer "Sorry, you haven't opened the app before! You need to download the events at least once to display it!"
put empty into events
end if
end if
answer "Events:" & return & events
put events into field "events"
answer events
When it wasn't connected to internet, it came up with "There's a file!", so it was able to find "Events.lc". Then it came up with the events, meaning it read the file properly and put it into events. Then it came up with "Events:", followed by the events, which worked, and finally just a messagebox of the events, from the last line. But even with all of that, put events into field "events" didn't make the list of events show up in the field!
I can't for the life of me figure out why it's not working. It's probably something tiny I'm missing. I was using the same code before I added the offline connectivity bit (so just the if offline=false part), and it worked fine. But for some reason, even though it's got events from the file, it's just not populating the field with it
So, I've been adding features to my app and all that, and have come across a problem. Since the app is showing a list of events that are coming up (which is read from a dropbox link), I want to make it so that if the user isn't connected to the internet, it will still show the latest version of the events that is was able to download. Here's the code I've got so far:
(this part is on the splashscreen)
put false into connected
put false into offline
put "Keep trying" & return & "Offline mode" & return & "Exit" into conoptions
repeat while connected is false
put url ("http://www.google.com?timestamp="& the milliseconds) into testurl
if testurl is empty then
mobilepick conoptions
if the result=1 then
put false into connected -- keeps trying to connect to internet
else if the result=2 then
put true into connected
put true into offline -- offline mode
else if the result=3 then
quit -- exit
end if
else
put true into connected
end if
end repeat
This bit works perfectly. This next bit is on the main card:
if offline is false then -- get dropbox version of file
put specialfolderpath("Documents") & "/Events.lc" into eventsdl
if leader=true then
put url "Leader Dropbox link" into events
else
put url "Dropbox link" into events
end if
put events into url ("file:" & eventsdl)
else if offline is true then -- get previous version of file if there is one
put specialfolderpath("Documents") & "/Events.lc" into eventspath
if there is a file eventspath then
open file eventspath for read
read from file eventspath until eof
put it into events
close file eventspath
else
answer "Sorry, you haven't opened the app before! You need to download the events at least once to display it!"
put empty into events
end if
end if
put events into field "events"
Now, it all seems to work well - I can put answer {variable} where needed and it will all show up. So, answer events shows a messagebox with events, answer offline shows the status of offline etc. The issue is the last line, put events into field "events". For some reason, the code works when it's connected to internet, but when it's not, it doesn't put events into field "events". I even had a bunch of answer lines in thee to see where it was up to, like this:
else if offline is true then
put specialfolderpath("Documents") & "/Events.lc" into eventspath
if there is a file eventspath then
answer "There's a file!"
open file eventspath for read
read from file eventspath until eof
put it into events
close file eventspath
answer events
end if
else
answer "Sorry, you haven't opened the app before! You need to download the events at least once to display it!"
put empty into events
end if
end if
answer "Events:" & return & events
put events into field "events"
answer events
When it wasn't connected to internet, it came up with "There's a file!", so it was able to find "Events.lc". Then it came up with the events, meaning it read the file properly and put it into events. Then it came up with "Events:", followed by the events, which worked, and finally just a messagebox of the events, from the last line. But even with all of that, put events into field "events" didn't make the list of events show up in the field!
I can't for the life of me figure out why it's not working. It's probably something tiny I'm missing. I was using the same code before I added the offline connectivity bit (so just the if offline=false part), and it worked fine. But for some reason, even though it's got events from the file, it's just not populating the field with it