Page 1 of 1

Saving data in text field on multiple cards

Posted: Mon Dec 07, 2009 12:24 am
by urbaud
I have a stack with 15 cards. Each has one has one text entry field on it and several buttons: new card, previous card, next card, first and last cards and save and open cards. It’s sort of a small freeform database. It works well other than the fact that I can’t save the data on all the cards. My save code will only save the data on the current card. How do I write code that will save and open the data on all 15 cards? My save and open code is below. I have tried to find a reference or link to some place that shows how to save all the cards to no avail. Any help would be much appreciated.

Code: Select all

on mouseUp  --save data
   open file "dbData" for update
   write fld "t1" to file "dbData"
   close file "dbData"
end mouseUp

on mouseUp  --open data
   open file "dbData"
   read from file "dbData" until end
   close file "dbData"
   put it into fld "t1"   
end mouseUp

Re: Saving data in text field on multiple cards

Posted: Mon Dec 07, 2009 9:29 am
by ale870
Hello,

using write fld "t1" to file "dbData" you overwrite the entire file content everytime!

If you want to use your RunRev application as a database front-end you need to manage data INSERT (append line in file), DELETE (remove line in file), UPDATE (change line in file), and SELECT (read file and show contents).

One simple way to do that (but it could become slow with many data) is reading the whole file in memory (put in a variable), and change every single line (when you change the data inside a card). When you completed, you can save the file modified.

Another option is you load the file, re-create all cards, then when the user save data, you can read all cards, compose a new text file, and save all.

Another way is using "seek" command (see the documentation).

One question: RunRev works well with many data, co why don't you create a group background and use RunRev to store them without using an external TEXT file? (you can create a substack that holds data like your text file).

Re: Saving data in text field on multiple cards

Posted: Mon Dec 07, 2009 11:30 am
by bn
Urbaud,
you can write your data out into one file instead of a database. But you would have to also write a delimiter to the file where the data of field "t1" of each card starts.
You could say something like this

Code: Select all

on mouseUp  --save data
   open file "dbData" for update
   repeat with i = 1 to the number of cards
     go card i
     write "#beginn of card " & the id of this card & return to file "dbData"
     write fld "t1" to file "dbData"
   end repeat
   close file "dbData"
end mouseUp
when retrieving the data you would open your file and look for "#beginn of card " with the offset function repeatedly. After "#beginn of card " you know you find the id of the target card and then you would put the the content of the field "t1" into field "t1" of the respective card.
This is just a sketch to show a way how to approach this short of using a database.
regards
Bernd

Re: Saving data in text field on multiple cards

Posted: Mon Dec 07, 2009 9:08 pm
by urbaud
Hi ale870 and bn,
Ale870, with all due respect, I don't think I understand what you're telling me in your reply to my post. Unfortunately, you're communicating with a relative newcomer to Rev. I wish I knew more, but I don't. Even if I did understand, I don't think I could write the code to do what you suggest.

bn, I haven't had a chance to use your code in my project yet. What would the open or read code look like. I've just downloaded Dan Shafer's book and have started to read it. I also need to delve into the Rev User's Guide. By the way, I notice that you live in Germany. My father's parents were born in Austria and my last name is Urbauer. Don't know if you've ever heard that name before.

Thank you both for replying so quickly to my post. I will try to do some of what you suggest, ale870, although not sure of success and bn, I'll use your code in my project. Thanks again for your help.

urbaud

Re: Saving data in text field on multiple cards

Posted: Mon Dec 07, 2009 9:28 pm
by bn
Urbaud,
funny change of name from Urbauer to Urbaud. Urbauer is not frequent but not unheard of in Germany. I dont know any Urbauer although according to the white pages there is one living in my hometown.
I worked once for 4 month on a farm in British Columbia, Smithers, have very fond memories of that.

I like the book by Dan Shafer, it helped me a lot when I started. And I should have followed his advice more closely...
So I learnt it the hard way.
Re your stack: You don't have to save the content of a field to a file, as you probably know. The stack saves the content of the field too. If you explain what exactly you want to do with the file it is easier to help you with this. If you are ready to go on feel free to ask again.
regards
Bernd

Re: Saving data in text field on multiple cards

Posted: Mon Dec 07, 2009 11:02 pm
by ale870
urbaud wrote:Hi ale870 and bn,
Ale870, with all due respect, I don't think I understand what you're telling me in your reply to my post. Unfortunately, you're communicating with a relative newcomer to Rev. I wish I knew more, but I don't. Even if I did understand, I don't think I could write the code to do what you suggest.

bn, I haven't had a chance to use your code in my project yet. What would the open or read code look like. I've just downloaded Dan Shafer's book and have started to read it. I also need to delve into the Rev User's Guide. By the way, I notice that you live in Germany. My father's parents were born in Austria and my last name is Urbauer. Don't know if you've ever heard that name before.

Thank you both for replying so quickly to my post. I will try to do some of what you suggest, ale870, although not sure of success and bn, I'll use your code in my project. Thanks again for your help.

urbaud
Hello,

I think every member in this great community tey to help other people as much as possible. As @bn said, since you are a beginner, you could better explain us what you want to do, so we can give you more precise information.
One thing more: if you don't know RunRev very well, instead to start making a DB-like system, try to make easier programs.
For example (thinking to your final target) you could start with some exercises working with files. Then learn the concepts of stack, substack and cards and its characteristics.
Use the embedded PDF guide (user guide) inside RunRev: that guide is very good for beginners (I'm not a beginner but I still use it so much!).

Cheers!

Re: Saving data in text field on multiple cards

Posted: Tue Dec 08, 2009 1:17 am
by urbaud
Hi ale870 and bn,
Thanks ale870 for your reply. In your reply you wrote: One question: RunRev works well with many data, so why don't you create a group background and use RunRev to store them without using an external TEXT file? (you can create a substack that holds data like your text file). My question back to you is how would I do that? How do I create a substack that would hold the data or a group background (I don’t even know what a group background is)? Also, you asked me to explain what I am trying to do. When I started this project I didn’t have a database in mind, but I guess that’s what it’s turning out to be. What I want to do is to be able to enter unique data into each card (in the text field “t1”on each card) and then be able to navigate between the cards, hence the next, previous and last etc. buttons. I also want to be able to add, delete, update the text in each card (if I choose to) and then save that unique text in each card to an external text file. When I open the external text file it would read the data and place the correct text back (updated or not) in the correct card. I have another project I wrote using only one card and one text field for keeping bits of information. It saves the text to a text file and then opens it with the original and updated text. So, I thought could I write a program that would have more than one card in it for text, hence this current project. I hope this makes it clear as to what I want to do. If either of you think there is a better or more efficient way of achieving this, by all means tell me about it and help me with the code. Thanks in advance for any help you can provide.

Oh, and Bernd, I haven’t changed my name from Urbauer to Urbaud. The urbaud is the login name I use at work. It’s the first 5 letters of my last name and the first letter of my first name, which is Dan. All of us at work have login names created like this. I’m also glad you enjoyed your 4 months in Smithers, BC. Because of that time you likely know how beautiful the Rocky Mountains are. No wonder they call BC, SuperNatural British Columbia. Again, thanks for your suggestions and hope to hear from one or both about a better way to do my project.

Re: Saving data in text field on multiple cards

Posted: Tue Dec 08, 2009 1:57 am
by ale870
Hello,

first of all: take a look to the user guide -> CHAPTER 2 ("Getting started", and "Structuring your application").
Well, you can "divide" your project in two steps:

STEP 1:
1.a) Create some fields, labels, and navigation buttons. Include even a button called "Save" (you can avoid this, but you need to call a "save this stack" every time you need to save data).
1.b) Group them (select and group them).
1.c) Edit group properties and select the option "Behave like a background".
1.d) In the navigation buttons use the commands "go prev card" / "go next card" / "create card" / etc... to manage cards (see Dictionary and User guide).

Well, basically speaking, your program is ready!

Now, talking about cards export, you need to consider some "factors":
1) do you really need to export data in a text file?!
2) a database could contain any kind of complex data (even images). Furthermore, data could be created like a "tree". Maybe it could be better if you make an exported based on xml (flat text file has many limitations, even for bad "node" management, multiline management, etc...). XML is a standard, and can manage any kind of data.
(my 2 cents suggestion!).

--Cheers!

Re: Saving data in text field on multiple cards

Posted: Tue Dec 08, 2009 2:02 am
by ale870
Ops... I forgot: I'm opening a new site, for RunRev, regarding widgets, tutorials, tips & tricks. Maybe this could be good material for the first tutorial :-)
It is almost completed!
http://runrevwidgets.com/wiki

Re: Saving data in text field on multiple cards

Posted: Wed Dec 09, 2009 1:35 am
by urbaud
Hi ale870,
Thank you for your most recent reply. Your advise to use the "save this stack" command seems to be the easiest way to achieve what I want. I've already built the interface: text boxes, and navigation buttons (they work fine), and thanks for the info on how to group them, etc. I think that saving the stack is all I need, as I can easily update each card's text if I want, then save it. And, I don’t need a “Open” button. You were right, I don’t really need an external file. So, thanks for that tip.

When do you think you’ll have the tips & tricks and tutorial sections completed at your RunRevWidgets website?, 'cause I'll certainly look at them.

Re: Saving data in text field on multiple cards

Posted: Wed Dec 09, 2009 2:46 am
by ale870
Hello,

I'm creating a widget to make export and import for CARD<->XML, automatically :-) (I hope to be able to complete it in two or three days).

One question: can you suggest me which tutorial or tips&tricks you would like exactly?

Re: Saving data in text field on multiple cards

Posted: Wed Dec 09, 2009 11:43 pm
by urbaud
Hi ale870,

In your last reply you asked if I could suggest some tutorials and/or tips & tricks that I would like to see. I do. First, I want to make a few comments. I use the dictionary in Rev a lot, but find that the examples are poor and often if I copy them and put them into my program they don’t work. There are some where the syntax is incorrect so I’ve spent hours figuring out the correct syntax. So, whatever tutorials or tips & tricks you develop, make sure the syntax is correct and the script actually works. I’ve done adult teaching and the single most effective way to help adults learn is by showing them i.e.. Through examples, examples and more examples. Go wild on well commented examples in your tutorials. I guarantee that if you’re able to achieve this in your tutorials you’ll be asked to create more. MAKE YOUR TUTORIALS DIFFERENT THAN THE TYPICAL TUTORIAL BY USING PLAINER LANGUAGE AND EXCELLENT EXAMPLES.

Also, the dictionary assumes that the person reading it has a programming background so a lot of the language used is “programming lingo.” Use it, but also state in non-programmer language what you’ve said in the programming language. For example, the following is directly out of the dictionary in the comments section of the answer file command: “If the as sheet form is used, the dialog box appears as a sheet on OS X systems. On other systems, the as sheet form has no effect and the dialog box appears normally. Attempting to open a sheet from within another sheet displays the second stack as a modal dialog box instead. To give a dialog box a prompt when using the as sheet form a non-empty title must be provided. This will cause the prompt to appear in the same place it would if as sheet was not being used.” For a newbie, this is tough to understand, so when your building the tutorials, use more every day language. Obviously, you’d have to define some of the terms.

If you decide to include this type of syntax:
answer file[s] prompt [with defaultPath] [{with filter | of type} types] [titled windowTitle] [as sheet] then show with examples each one of the various ways the answer command can be used. I still don’t know what all those symbols mean and I would have a hard time writing an example to show each possibility. Like what does [{with filter | of type} types] mean? Explain it by example.

Now, having said all that, here are some suggestions for tutorials or tips & tricks:

1. Build a program that uses Menus. Make the tutorial about creating menus.
2. A program showing how to read and write to text and binary external files.
3. Error handling in a program. Maybe an example with error handling and the same one without it.
4.Message hierarchy, inheritance, stacks and substacks. Make a tutorial so anybody could understand these terms. And, of course, use well commented examples.
5. How to use offset and when and where to use it. Probably something about chunks would have to be part of it.
6. This is a tough one. Build a program, that’s reasonably complex, to try to show the use of the most frequently used commands, with line by line explanations of what each line of code does and why.
7. Graphics, audio, video and the Web would be future tutorials. Personally, I don’t have much interest in building a program that would connect with the Internet, but I’m sure there are many others who would.

That’s about it. If I think of other examples I’ll somehow contact you. Oh, by the way, I was thinking about my current project where I am using your suggestion: save this stack. I thought, what if I make the project a standalone app, then the save this stack doesn’t work. So, if you’re willing I’d like some help to learn how to write and read external files as per my current project. Thanks again for your help and suggestions.

Re: Saving data in text field on multiple cards

Posted: Thu Dec 10, 2009 12:11 am
by bn
Dan,
since you have Shafer's book he explains very well the menu-thing and how to save a stack when you build a standalone. Because the mainstack of a standalone can not be saved, but a second stack you include in your standalone can be saved. So this method is often referred to as the splash-screen method: the mainstack is only to start your program, opens the second stack you want to change data in that can be saved and then the mainstack hides itself.
Also have a look at the tutorial stacks in the resource center in the help menu, I think they are pretty good.
Also http://lessons.runrev.com/
Also http://support.runrev.com/scriptingconferences/
regards
Bernd

Re: Saving data in text field on multiple cards

Posted: Thu Dec 10, 2009 2:01 am
by ale870
Thank you @urbaud for your comments and suggestions, I really appreciate them!
First of all, a news for you: I completed the widget to export data (fields grouped and marked as "behave like a background") from cards to xml. THe process is automatic. You simply need to setup some properties. Try to download the widget from here:

http://runrevwidgets.com/wiki/tiki-list ... alleryId=3

It is UTIL-001_CardsExporter.rev. There is a small but clear description inside the component REV. I will write a new topic in the forum to supply more details about it.

I will "schedule" the tutorials, in order to write them. I think some of them will be "converted" to tips & tricks.

In the past, I already explained programming languages to many people, but of course, as you said, it is not possible to explain a programming language to a person that never saw a computer... a minimal knowledge is required :-)

About the problem regarding stack saving:
That’s about it. If I think of other examples I’ll somehow contact you. Oh, by the way, I was thinking about my current project where I am using your suggestion: save this stack. I thought, what if I make the project a standalone app, then the save this stack doesn’t work. So, if you’re willing I’d like some help to learn how to write and read external files as per my current project. Thanks again for your help and suggestions.
Follow what @bn said, it's a very good suggestion. I wish to add one small thing more to it:
He talked about "a second stack". You can do that in two ways:
1) Create two applications (two main stacks). But only one of them will be converted to standalone.
2) Create a single program (a main stack and a sub-stack), then, when publish it, go to menu FILE->STANDALONE APPLICATION SETTINGS -> STACKS then enable the option Move the substacks into individual files. In this way RunRev will create an executable with main stack, but will convert all substacks to standard "*.rev" stacks (which can be saved).

Let me know if you like the converter, and take a look to my blog, since very soon you will find the first tutorial ;-)

Cheers!