Beginner's problem with variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 8
- Joined: Sun Nov 16, 2014 3:05 am
Beginner's problem with variables
Hi Guys
I’m a complete novice with Livecode and I’ve just started exploring variables. However I cannot seen to get this to work, and I can’t suss out what I’m doing wrong, so I’d be grateful of any help. I have a main stack called APPDMS. In the stack script I have defined a global variable gvarconnum like this;
Global
gvarconnum
On the first card I have a field called PSB-con-num which contains the following script;
on returninfield
end returninfield
on enterinfield
end enterinfield
on textChanged
put me into field "PSB-Con-num-title"
end textChanged
on textChanged
put me into gvarconnum
end textChanged
The first ‘on textChanged’ works fine. On the second card I have a field into which I want to put gvarconnum using this script for the field;
on preOpencard
put gvarconnum into me
end preOpencard.
When I open the second card the field displays the word gvarconnum rather than the value entered on the first card. What am I doing wrong?
Thanks
Stephen
I’m a complete novice with Livecode and I’ve just started exploring variables. However I cannot seen to get this to work, and I can’t suss out what I’m doing wrong, so I’d be grateful of any help. I have a main stack called APPDMS. In the stack script I have defined a global variable gvarconnum like this;
Global
gvarconnum
On the first card I have a field called PSB-con-num which contains the following script;
on returninfield
end returninfield
on enterinfield
end enterinfield
on textChanged
put me into field "PSB-Con-num-title"
end textChanged
on textChanged
put me into gvarconnum
end textChanged
The first ‘on textChanged’ works fine. On the second card I have a field into which I want to put gvarconnum using this script for the field;
on preOpencard
put gvarconnum into me
end preOpencard.
When I open the second card the field displays the word gvarconnum rather than the value entered on the first card. What am I doing wrong?
Thanks
Stephen
Stephen
www.landscapesofwales.co.uk
www.landscapesofwales.co.uk
Re: Beginner's problem with variables
Hi Stephen,
Welcome to the forum
There is a not so apparent thing about globals... they must be declared everywhere they are used.
But first the word global and the variable should be on one line e.g.
to add more you just put a comma in
Now in the field and on the second card you must declare the global
and then in the second card.
Lots of fun ahead!
Simon
Welcome to the forum

There is a not so apparent thing about globals... they must be declared everywhere they are used.
But first the word global and the variable should be on one line e.g.
Code: Select all
global gvarconnum
Code: Select all
global gvarconnum,gMyvar,gTimeRightNow
Code: Select all
global gvarconnum
on returninfield
end returninfield
on enterinfield
end enterinfield
on textChanged
put me into field "PSB-Con-num-title"
end textChanged
on textChanged
put me into gvarconnum
end textChanged
Lots of fun ahead!
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 8
- Joined: Sun Nov 16, 2014 3:05 am
Re: Beginner's problem with variables
Simon.
Many thanks for the quick reply. I've declared the global gvarconnum in the script for the stack, both cards and both fields, but without success. I'll put it down for a few hours and when I come back to it my error my be obvious.
Stephen
Many thanks for the quick reply. I've declared the global gvarconnum in the script for the stack, both cards and both fields, but without success. I'll put it down for a few hours and when I come back to it my error my be obvious.
Stephen
Stephen
www.landscapesofwales.co.uk
www.landscapesofwales.co.uk
Re: Beginner's problem with variables
oops!
I totally missed you have 2 on textChanged
No no
just use the one.
Simon
I totally missed you have 2 on textChanged

No no
Code: Select all
on textChanged
put me into field "PSB-Con-num-title"
put me into gvarconnum
end textChanged

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Beginner's problem with variables
hmmm and
use that in the card script.
Not sure that preOpenCard gets sent to a field.
Simon
Code: Select all
global gvarconnum
on preOpencard
put gvarconnum into field "theFieldWhereIWantIt"
end preOpencard.
Not sure that preOpenCard gets sent to a field.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 8
- Joined: Sun Nov 16, 2014 3:05 am
Re: Beginner's problem with variables
Works a treat now Simon. Thank you.
Stephen
Stephen
Stephen
www.landscapesofwales.co.uk
www.landscapesofwales.co.uk
Re: Beginner's problem with variables
Hi Stephen,
Great photos!
I lived in Wales for a few years a very long time ago.
Glad the variable is working for you.
Simon
Great photos!
I lived in Wales for a few years a very long time ago.
Glad the variable is working for you.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Beginner's problem with variables
Yeah, it would work.Simon wrote:.
Not sure that preOpenCard gets sent to a field.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 8
- Joined: Sun Nov 16, 2014 3:05 am
Re: Beginner's problem with variables
HI Guys
Quick update on this. I want the variables to be available throughout the stack all the time, not just when the text changes, so I've put the following script in the main stack;
Works a treat now. Thanks for your input.
Quick update on this. I want the variables to be available throughout the stack all the time, not just when the text changes, so I've put the following script in the main stack;
Code: Select all
global gvarconnum,gvarclientname,gvarcontitle,gvarclientcon,gvarappcon
on openStack
put field "PSB-con-num" into gvarconnum
put field "PSB-client-name" into gvarclientname
put field "PSB-Con-title" into gvarcontitle
put field "PSB-client-con" into gvarclientcon
put field "PSB-APP-con-name" into gvarappcon
end openStack
Stephen
www.landscapesofwales.co.uk
www.landscapesofwales.co.uk
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Beginner's problem with variables
Or if you're a lazy typist you can store all those values in one array:
Code: Select all
global gvarVA
on openStack
repeat for each item tItem in "con-num,client-name,Con-title,client-con,APP-con-name"
put fld "(PSB-"& tItem) into gvarA[tItem]
end repeat
end openStack
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Beginner's problem with variables
Ah, that lazy approach is lovely 

-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Beginner's problem with variables
LiveCode's associative arrays are wonderful things, useful in so many contexts - we've barely scratched the surface here. And if you need to store their contents, we have arrayEncode and arrayDecode so that they can be written to and read from disk as well. So many things become simple and efficient with arrays....
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn