String and field commands

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
p4tr1ck
Posts: 36
Joined: Mon Jun 14, 2010 4:58 pm

String and field commands

Post by p4tr1ck » Mon Jun 14, 2010 5:27 pm

Hello and thanks for reading.
For my first project in Revolution (technically my second, I have made a guessing game), I figured I would try out a calculator, looking very similar to the standard Windows calculator. I figured that I would treat the output of the calculator (the field) as a string that could be converted to a real value when performing math, making it easier to make something like "4" into "40".
This being my first real project, I know very little commands (but I do know the syntax), so I have a few questions to ask.
-How do I make it so that the user cannot type into the output field? Is this possible in the inspector somewhere?
-How do I add one string value to the end of another? When trying the add command, even while using parentheses with the numbers, it treats them as integers and adds them mathematically.
-How do I convert a real/integer to a string, and vice versa?

Thanks for reading,
Patrick

Curry
Posts: 111
Joined: Mon Oct 15, 2007 11:34 pm
Contact:

Re: String and field commands

Post by Curry » Mon Jun 14, 2010 10:48 pm

1. Yes, in the Inspector, "Lock Text" checkbox
2. put newChar after myString
or: put oldString & newChar into newString
3. Type conservation is automatic (it happens when needed, or it can be forced with +0 or &"") but remember to filter input to avoid errors!
Best wishes,

Curry Kenworthy

LiveCode Development, Training & Consulting
http://livecodeconsulting.com/

WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/

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

Re: String and field commands

Post by dunbarx » Tue Jun 15, 2010 2:52 pm

Curry is correct on all three counts, I am just going to expand a bit:

1- Read about the "lockText" property. And yes, this is settable in the inspector.
2- Go to the dictionary and enter "&". You will be "concatenating". Check out "&&".
3- This is pretty automatic. The engine interprets numbers and strings purely based on context, typing on the fly. So if you say:
"put 2 + 2 into total", you will get a "4". If you say "put 2 + x into total" you will get an error. The only time you ever need to worry about such things is when you want to control the way output is displayed. Read about "format" and "numberFormat".

Ask anything.

Craig Newman

Post Reply