Displaying text and some other Q's

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Rf928
Posts: 10
Joined: Tue Apr 02, 2013 5:59 am

Displaying text and some other Q's

Post by Rf928 » Tue Jul 02, 2013 5:40 pm

Hello,

I have a couple of questions

What I am trying to do is have an empty field. There is a button next to it, user presses button, and what is in the field is transferred to a label, or a fixed piece of text.

I have done:

Code: Select all

on mouseUp
   set the text of label "myLabel" to the text of field "myField"
end mouseUp
And it won't work for me. This is most likely super super simple, I have searched quite a bit and couldn't find any raw code, but bare with me if I missed something super obvious. Now if I wanted to make a selectable menu, either a pull-down or selectable, how would this work?

I assume the code is something like:

Code: Select all

on menuPick pItemName
   switch pItemName
      if pItemName is "Option 1" then doSomething --doSomething being the function (or handler) to add that selection to a label
   end switch
end menuPick
Now if this all worked, and I had a list of labels on a separate card all displaying information from the first card, I want to save it as a PDF. All in the same layout as the card, so I am assuming the code goes like this:

Code: Select all

on mouseUp
    print card from topLeft to rightBottom into pageRect --pageRect being the page I want to save/print
end mouseUp
Shouldn't that give me the option to print, then from there I can save the PDF? Or is there a way I can press a button, and boom, a PDF appears? I've looked, but again, couldn't really find anything that directly relates to what I am attempting to do.

Thank you,
rf928

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Displaying text and some other Q's

Post by jmburnod » Tue Jul 02, 2013 6:28 pm

Hi Rf928

For the text of an option menu

Code: Select all

on mouseUp
   --set the text of label "myLabel" to the text of field "myField"
   set the text of btn "MyButton" to (fld "myField")
end mouseUp
For the label of an option menu

Code: Select all

on mouseUp
   set the label of btn "MyButton" to line 1 of fld "myField"
end mouseUp
Sorry I have to move.
Kind regards
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Displaying text and some other Q's

Post by dunbarx » Tue Jul 02, 2013 9:07 pm

Jean-Marc is on the move, but answered some of your questions before he left.

Just to clarify. "Label" is a property, usually of a button, so your idea was not crazy, but was syntactically incorrect, in that you treated that word as an object reference.

You are starting out using switch control structures. Good. Read up on these again in the dictionary. In the way you wrote it, and there are a few forms this can take, you would need "case" keywords to make it work:

Code: Select all

on menuPick pItemName
      switch pItemName
      case "choice 1"
     --doSomething being the function (or handler) to add that selection to a label
   end switch
end menuPick
Experiment with the various ways "switch" control structures can be used. They are very powerful and readable. Watch your breaks.

Read also about the "open printing to PDF" in the dictionary.

Write back when you get stuck again. This is all normal behavior during the learning process.

Craig Newman

Rf928
Posts: 10
Joined: Tue Apr 02, 2013 5:59 am

Re: Displaying text and some other Q's

Post by Rf928 » Wed Jul 03, 2013 12:09 am

When I said label, I meant the object 4th down on the left row on the menu-tool thing. But I did what you said, and it worked great! However, is there a way to limit the entry of a text field to one line? I found one topic on it, and it totally blew my mind.

Another thing I forgot, that is rather important, is the fact that when the user closes this, the format and changes are lost. Is there a way I can save a .xml or some kind of file to keep the format/layout of each time they add this info in, in the case that they want to change it? If that makes sense..

Now onto printing/PDF, hopefully that isn't too complex :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Displaying text and some other Q's

Post by dunbarx » Wed Jul 03, 2013 1:03 am

Good to hear you are moving along.

The fourth thing down from the menu-tool thing??? That is the tools palette, and the fourth thing down is a field, preset to be a label field. But there is only one kind of field, and the various styles they come in are set by adjusting properties.

When your mind was blown with the one liner, did you work out a solution? Or is this still a problem?

What changes? Closes what? The stack? Have you saved the stack?

Or are you working in a standalone? If so, the issue might be that you cannot save the executable in a standalone, but rather must attach other stacks to the stack file in the "Standalone Applications Settings" dialog. All changes are made to those other stacks, the "parent" stack being merely a placeholder, or a "splash" screen. There are a few ways to do this. Write back...

Craig Newman

Rf928
Posts: 10
Joined: Tue Apr 02, 2013 5:59 am

Re: Displaying text and some other Q's

Post by Rf928 » Wed Jul 03, 2013 2:51 pm

Sorry, my lack of knowledge of terms used in this SDK are showing, I apologize.

No, I did not figure out how to limit to one line. Here is the link: viewtopic.php?f=8&t=14415 that I saw, but it didn't make a lot of sense to me.

What I have, is a program where on one card you enter a bunch of data, and press a button. That takes all of the data and lays it out nice on another card, and it is saved to a PDF. My first problem, is LC doesn't seem to make objects like fields "global" between cards. Is this true? If so, is there a way to "require" the other card and gain access to its objects? My second problem, is once the user closes my program, if they wanted to make changes to the data they are adding they cannot. They must enter it again. Is there a way to "save last settings" or something like that? Mind you, this takes place after the application has been saved as a standalone. Does that make sense?

I am shocked at the level of help I am receiving, no other SDK has ever assisted me this much! I will keep replying until I get everything I need :)

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Displaying text and some other Q's

Post by jmburnod » Wed Jul 03, 2013 5:47 pm

Hi Rf928

If I understand what you mean, you need a fld shared between two or more cards
You can do that like this
1. Create a fld
2. Click on the "group" button of the toolsbar
You are created a group with one fld
3. set the BackgroundBehavior of this group to true
Each card you will create will have this group
To manage groups have a look to "place group" and "remove group"

• Sharing the text of the fld
4.If you want share the text of the fld between, set the sharedtext of the fld to true

•Save last setting
Yes, you can and you have to do it standalone is read only. I use a simple text file to export date and I read it on openstack

• Help quality
I hope you we will hear about you when you solved your stuff. That is the recipe for a good collective help

Kind regards
Jean-Marc
https://alternatic.ch

Rf928
Posts: 10
Joined: Tue Apr 02, 2013 5:59 am

Re: Displaying text and some other Q's

Post by Rf928 » Wed Jul 03, 2013 7:13 pm

Back up a bit.

-Created field (4th down, left row on the tools palette)
-Create group out of field
-Name Group "myGroup
-Open myGroup script
-Add this code to the group script

Code: Select all

set the sharedText of group "myGroup" to true
set the backgroundBehavior of group "myGroup" to true
-Go back to first card, in the button script I add

Code: Select all

on mouseUp
   set the text of group "myGroup" to (fld "myField")
end mouseUp
And it seems to be failing. What am I missing?

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

Re: Displaying text and some other Q's

Post by Klaus » Wed Jul 03, 2013 7:53 pm

Hi Rf928,

do yourself a favour and work through these stacks to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Displaying text and some other Q's

Post by dunbarx » Wed Jul 03, 2013 10:27 pm

Klaus is right, you need to slow down.

You dived into LiveCode with a vengeance, and have fallen into a not uncommon trap; you are way ahead of yourself. Because LC seems so english-like, it is tempting to simply write code that seems logical and straightforward.

But LC is far too rich to simply jump in and make applications. There is a formal syntax to the language, and a formal structure to the IDE. For example, you cannot set the text of a group. It does not make sense. You can, however, set the text of an object that holds text, like a field.

How could you know the difference? Go through the lessons and tutorials. BY ALL MEANS try to make programs right away. But you are asking questions prematurely; you have not struggled enough. We are indeed ready to work with you endlessly, but you must first be at just a slightly higher level, with the basic mechanics well in hand. In other words, we do not want to teach you LiveCode from the beginning. That is your job. We want to teach you technique and solve your problems.

You do not sound like someone who is easily discouraged. Good. Neither are we.

Craig Newman

Rf928
Posts: 10
Joined: Tue Apr 02, 2013 5:59 am

Re: Displaying text and some other Q's

Post by Rf928 » Thu Jul 04, 2013 12:53 am

I certainly appreciate the help and advise, and believe you are correct.

What I really am having problems with, is coming from C and Lua and other languages like that, this is WAY too simple, is very hard to grasp compared to standard programming. The issue for me, is how things are done in the LC syntax. I know what I need to do, I might even know the right keywords but the thing I don't know (yet) is how things are piled together. Things I learn with more reading.

I don't understand when you know where to apply the script, being a card or an object. I understand the Message path, just not where things are done. Is it possible to create a program in the stack script? Then have functions (Handlers?) pass things to that script, is the stack globally accessible?

If you understand where I come from :P

This is almost too easy, but I do have the basics of how programming is done in LC figured. And I do LOVE the IDE!

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Displaying text and some other Q's

Post by jmburnod » Thu Jul 04, 2013 8:47 am

H Rf928,

• LC Almost too easy
Yes, you're right. LC way is often simpler than other langages and I understand that is difficult for C programmers

• program in the stack script
Yes. You can have all handlers, function etc... in stack script and use them from objects.

All the best
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Displaying text and some other Q's

Post by dunbarx » Thu Jul 04, 2013 11:04 pm

What Jean-Marc said.

If you had a button with this in its script:

Code: Select all

on mouseUp
 beep the number of me
end mouseUp[/code}

Now this has its own peculiar aspects, such as "the number of me", but I use it to illustrate a point. If the button was the fourth one created, it would have "4" as its "number" property. It would beep four times when clicked. If you had this script in each of the other buttons, they would beep the appropriate number of times. Better that explicitly writing "beep 4" for that button.

If you had this in the card (or stack) script:[code]on mouseUp
 beep the number of the target
end mouseUp[/code}

You would only need that one handler to manage as many buttons as might be present on the card. "The target" (read about it) would determine the appropriate value. No matter if you add or subtract buttons, the code is robust. In other words, read up on the message hierarchy. Keep plugging away.

Craig

Post Reply