What code would you use?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

What code would you use?

Post by user#606 » Mon Jul 08, 2013 1:16 pm

I have a Contact manager program that I use on PC and MAC.
Big Deal I hear you say, but it has brought me in a great deal of business that I would never have got, without it. Trust me, the commercial stuff is rubbish, you need a real world application to do the job.

The issue is that I tried it on a Galaxy note 10.1 and apart from the file handling, it works very well. It looks just like it would on Mac or PC, No stupid icons etc.

I use this to save on PC or Mac (and it even saves and recalls from skydrive without mods).

local recalledfile
on mouseUp
answer file "Select a text file:" with type "Contact Manager|mge|"
if it is empty then exit mouseUp
put it into recalledfile
put recalledfile into field "FilePath"
--set the itemdelimiter to tab
put "file:" & recalledfile into recalledfile
put url recalledfile into Field "TempTable1"

RecallFromDisk -- Recalled data file manipulation

priority
--Enable buttons after initial startup with data
--enablesysbuttons
enable field id 1004 --Table Field
enable button id 1173 --Change Database
--For safety, dsisable OPEN & AS until SAVE or AS
disable button id 1093 --Open
disable button id 1017 -- A
end mouseUp

I use this to recall the file

local counter, tFileDatax, MyFileName
on mouseUp
set the itemdelimiter to tab
-- bring up the system standard file selector to choose a file on disk
--ask file "Please select a file:" with filter "Contact Manager,*.mge"
ask file "Enter file name:" with type "Contact Manager|mge|"
-- if cancel is clicked, exit
if it is empty then exit mouseUp
-- display the file path in the File Path field
put it into MyFileName
-- load the contents of the file, into a variable
if MyFileName ends with ".mge" then
put "File:" & MyFileName into MyFileName
else
put "File:" & MyFileName & ".mge" into MyFileName
end if

SavetoDisk --Common save data code in stack script
set the itemdelimiter to tab
put field "Table 1" into url MyFileName
--For safety, enable OPEN & AS until SAVE or AS
enable button id 1093 --Open
enable button id 1017 -- As
put Field "TempTable1" into field "Table 1" --Puts page content back as it was before save
priority
end mouseUp

What I actually need now is the changes that would allow the above to save on an Android tablet.
Can any one help please?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: What code would you use?

Post by Klaus » Mon Jul 08, 2013 1:48 pm

Hi user#606,

since you cannot "ASK/ANSWER file..." on ANDROID, you will need to "automate" reading/writing your files on mobile!
Best do this in -> specialfolderpath("documents") where you have read and write permissions.
...
if the environment <> "mobile" then
## let the user save or choose a file on disk:
ask file "..."
else
## do automatic read/writing here
end if
...

OR if your want to let the user select a file:
...
set the folder to specialfolderpath("documents")
put the files into tFiles
filter tFiles with "*.mge"
put tFiles into field "the listfield, where you want the user to select one of the (prefs-) files"
...
Know what I mean?


Best

Klaus

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Re: What code would you use?

Post by user#606 » Mon Jul 08, 2013 2:35 pm

Hi Klaus,
Thank you for the help on this one.

It looks clear enough, but I will need to try it out to see what needs adjustment.

It is unlikely I will store data on the tablet, just to read amend and save from the main server, for the very rare situation that needs it.

altaqzmqa
Posts: 1
Joined: Sun Jul 28, 2013 3:14 pm
Contact:

Re: What code would you use?

Post by altaqzmqa » Sun Jul 28, 2013 3:21 pm

user#606 wrote: What I actually need now is the changes that would allow the above to save on an Android table.
Can any one help please?
Do you solve this problem now, i meet the same problem.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: What code would you use?

Post by Klaus » Sun Jul 28, 2013 4:22 pm

Hola altaqzmqa,
altaqzmqa wrote:
user#606 wrote: What I actually need now is the changes that would allow the above to save on an Android table.
Can any one help please?
Do you solve this problem now, i meet the same problem.
Do you mean saving something on a tablet on Android?
...
## Your app has WRITE permission in this folder!
put specialfolderpath("documents") & "/your_name_for_the_prefs_file_here" into tPrefsFile
put content_of_a_variable_or_whetever_you_want_to_store into url("file:" & tPrefsFile)
## Done :-)
...


Best

Klaus

Post Reply