DataGrids - Problems creating scripts

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
teasdlive
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 4
Joined: Wed Dec 07, 2011 1:39 pm

DataGrids - Problems creating scripts

Post by teasdlive » Thu Aug 15, 2013 10:10 am

Hi

I'm creating an iPad App for our distribution business and have managed to get quite a bit completed but now I'm having problems coding certain areas…if anyone can help please as I'm a designer and not too familiar with coding unless it's simple, having said that I do enjoy a challenge and learning, but I need examples to teach me how to put the scripts together!

Card one of the stack will have a DataGrid with 2 columns, one has a list of addresses serving a particular area (possibly 200 addresses). A single address is selected via a button in col 2 of the DataGrid which takes you to a card which will have the details of that one specific address.

This new card will have a data grid which contains columns as listed below.
The columns would be headed as Leaflets, Date, Amount, Type of Rack, Spinner Units

Leaflet column would be populated with List of customer leaflets (approx 26 different sorts)
"Date" Column will be a Date PickWheel
"Amount" column will be an Option Menu
"Rack Sizes" will be an Option Menu
"Spinner Units" will be a Check Box

I'm happy about creating this with DataGridHelper

But its the saving of the content which is losing me.I have the following script which saves a text file on the desktop in Mac.

on mouseUp
ask file "Save the data :" with "MyFile"
if it is empty then
beep
exit to top
end if
put "file:"&it&".txt" into thePath

--- we get the columns names
put the dgProp[ "column labels" ] of group "Datagrid 1" into theColumnNames
replace cr with tab in theColumnNames


-- with this method, we choose which column we want to save
-- here col1, col2,
put empty into theText
put the dgData of group "Datagrid 1" into theData
put the dgIndexes of group "Datagrid 1" into theIndexes

repeat for each item theIndex in theIndexes

put theData[theIndex]["Leaflets"] &tab&theData[theIndex]["Date"]&tab&theData[theIndex]["Amount"] &tab&theData[theIndex]["Rack Sizes"] &tab&theData[theIndex]["Spinner Units"]& cr after theText
end repeat

put theColumnNames&CR&theText into aTraiter
put aTraiter into URL thePath
answer info "Done"
end mouseUp

This works OK on the desktop, although I don't get the "date"
But when tested in iPad simulator although a message says "Done" I don't know what is happening to the file if anything?

My questions are, how would the scripts be compiled to achieve the questions asked below….

1. How do I write a script to save the DataGrid information to a text file? and also save it on the actual iPad if need be? A clear example would be great!
2. Can I save the information from approx 200 cards each containing their own DataGrid/s with one button click?
3. Can I have more than one DataGrid on each card and save that info as question 2?
4. Can I save the information in the DataGrids for the complete stack in one go?
5. I'd also like a button to reset the columns back to their unselected state in the DataGrids at the end of each week's deliveries.

I hope this is not too much to ask, but without help I'm really stuck.
Thank you
Brian

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

Re: DataGrids - Problems creating scripts

Post by Klaus » Fri Aug 16, 2013 12:26 pm

Hi Brian,
teasdlive wrote:...
This works OK on the desktop, although I don't get the "date"
But when tested in iPad simulator although a message says "Done" I don't know what is happening to the file if anything?
Hmm, the DATE should be included according to your script!

Problem is:
1. on iOS you cannot "answer file..."!
So this is the first step to disaster :-)

2. You are creating a filename:
...
put "file:"&it&".txt" into thePath
...
Do have an idea what IT is here? 8-)

3. Since you do not provide a valid filename on iOS, the SAVE operation will silently fail,
because in THAT case "the defaultfolder" will be the engine folder where your app does
NOT have write permission!
teasdlive wrote:1. How do I write a script to save the DataGrid information to a text file? and also save it on the actual iPad if need be? A clear example would be great!
You need to save everything automatically! in -> specialfolderpath("documents") on the mobile platform!
...
put specialfolderpath("documantes") & "/dgPrefs.txt" into tFilename
put the_data_from_datagrid into url("file:" & tFilename)
...
teasdlive wrote:2. Can I save the information from approx 200 cards each containing their own DataGrid/s with one button click?
Yes, if the button script is correct :-D
You need to LOOP (repeat) through all cards, collect the infos and then write to disk!
teasdlive wrote:3. Can I have more than one DataGrid on each card and save that info as question 2?
Yes, as may DGs as you like, see above...
teasdlive wrote:4. Can I save the information in the DataGrids for the complete stack in one go?
See #2 :-)
teasdlive wrote:5. I'd also like a button to reset the columns back to their unselected state in the DataGrids at the end of each week's deliveries.
What do you want to "reset" resp. what is "their unselected state"?
Sure this is possible!


Best

Klaus

teasdlive
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 4
Joined: Wed Dec 07, 2011 1:39 pm

Re: DataGrids - Problems creating scripts

Post by teasdlive » Mon Aug 19, 2013 2:49 pm

Hi Klaus

Firstly thank you for your reply.

I've been experimenting with your comments but still seem to be having lots of problems with something that ought to be straight forward I assume.

I've tried
put specialfolderpath("documents") & "/dgPrefs.txt" into tFilename
put the_data_from_datagrid into url("file:" & tFilename)

Which works on my desktop mac OK (although the text file says "the_data_from_datagrid" and nothing else) but nothing happens in the iPad simulator?

Would it be possible for you to point me to a solution for saving selected check boxes and data in a DataGrid/s on multiple cards until refreshed?
Saving the contents of a DataGrid/s to a text file on an iPad from multiple cards?
What is a LOOP repeat please and where would I find out about it?

I feel I'm going round in circles and uncovering so many forum questions and tuts that it is even more confusing. I've noticed that people have been asking the same questions as me for year's now?
Couldn't RunRev post a definitive solution to the saving issues on IOS?
Lots of Livecode tutorials expect the user to know how the scripts are written, I think there needs to be a far more basis set of tutorials for beginners!

Thats my little rant! Not aimed at you Klaus!

Thank you again for your help!

Brian

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

Re: DataGrids - Problems creating scripts

Post by Klaus » Mon Aug 19, 2013 3:57 pm

Hi Brian,
teasdlive wrote:...
I've tried
put specialfolderpath("documents") & "/dgPrefs.txt" into tFilename
put the_data_from_datagrid into url("file:" & tFilename)

Which works on my desktop mac OK (although the text file says "the_data_from_datagrid" and nothing else) but nothing happens in the iPad simulator?
Sigh...

Well, that was
1. a quick and dirty example to ilustrate WHERE to save something on an iDevce.
2. the variable in my example had NO content so far, and if a variable does not have any explicit content, its content will be its NAME!
3. Do I really need to name the variables in my example like:
...
put yet_empty_example_variable_which_you_may_need_to_fill_with_content_before_it_serves_a_meaningful_purpose__here_the_content_of_YOUR_datagrid into url("file:" & tFilename)
...
? 8-)

And are you sure that nothing will happen on the iOS SImulator?
Or maybe you just don't know where to look? :-)
Add a button with this script, click it in the Simulator and see WHERE exactly the simulator simulates the existence of your app on your Mac!

Code: Select all

on mouseup
  answer specialfolderpath("documents")
end mouseup
teasdlive wrote: Would it be possible for you to point me to a solution for saving selected check boxes and data in a DataGrid/s on multiple cards until refreshed?
Saving the contents of a DataGrid/s to a text file on an iPad from multiple cards?
What is a LOOP repeat please and where would I find out about it?
Sorry, maybe bad wording from me...
I mean of course a REPEAT LOOP throiugh all your cards:

Code: Select all

...
repeat with i = 1 to the num of cds
  put the dgtext of grp "DataGrid here" of cd i into url("file:" & specialfolderpath("documents") & "/dgprefs" & i)
end repeat

## Will ysave the content in numbered files: dgprefs1 -> for card 1 etc...
## No suffix necessary
...
This is just an example, please do not copy and pate it into your app and exspect it to work as exspected! 8-)

Please check also these stacks to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

Post Reply