the variable "it"

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
NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

the variable "it"

Post by NigelS » Fri Dec 16, 2011 9:30 am

I have field called fileName. On pressing a button to do a "answer file", the block of code is as such..,

on mouseUp
answer file "Please choose the INI file "
if the result is not "cancel" then
put it into field "fileName"
end if
end mouseUp

on inspection of the variable "it", "it" has a value, when doing the put into the field fileName, it remains blank.
I've tried different syntax but of no avail the field remains blank

What I'm trying to achieve is passing the value that's in filed "fileName" to a function, see code below.

on mouseUp
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",fileName) into messageText
end mouseUp

when inspecting the value of the passed field called fileName, I get the value fileName in the field called fileName.

any advice would be appreciated.
Attachments
Screen Shot 2011-12-16 at 10.22.27 AM.png

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

Re: the variable "it"

Post by jmburnod » Fri Dec 16, 2011 10:24 am

Hi Nigels,

Sorry if i dont understand what you want (my english is in progress :D )
when doing the put into the field fileName, it remains blank
Yes, it = empty after the end of the handler

if you want the content of the file

Code: Select all

on mouseUp
   answer file "Please choose the INI file "
   if the result is not "cancel" then
      put it into field "fileName"
   end if
  put URL ("file:"& it) into fld "MyField" 
end mouseUp
Best regards

Jean-Marc
https://alternatic.ch

NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

Re: the variable "it"

Post by NigelS » Fri Dec 16, 2011 10:47 am

jmburnod wrote:Hi Nigels,

Sorry if i dont understand what you want (my english is in progress :D )
when doing the put into the field fileName, it remains blank
Yes, it = empty after the end of the handler

if you want the content of the file

Code: Select all

on mouseUp
   answer file "Please choose the INI file "
   if the result is not "cancel" then
      put it into field "fileName"
   end if
  put URL ("file:"& it) into fld "MyField" 
end mouseUp
Best regards

Jean-Marc

Thanks for the reply Jean-Marc, let me see if I can simplify this.

In the field "fileName' is a path plus the name of the file that the program at a stage will open up and do a parse on it.
What I'm trying to do is to populate the field with whatever has been selected by the "answer file" command. If you look at the screen shoot you'll see it has that information.

Having gotten this information I then want to pass the contents of fileName to a function that will open this file and do a parse on the contents of the INI file.

I hope this explains a little better. :)
Attachments
Screen Shot 2011-12-16 at 11.41.07 AM.png

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm

Re: the variable "it"

Post by Bernard » Fri Dec 16, 2011 10:52 am

It is best to treat the "built-in" variables of "it" and "result" as transit containers, i.e. they are often used by various activities to store something.

If what is going to appear in "it" or "result" is of importance to your code, then get hold of the value ASAP in the code. So, immediately after an action that might result in data in "it" or "result", get that date out and store it in your own variable.

I never rely for more than a single step on what is in "it" and "result" - I put them somewhere that is mine so that I can be sure they do not change under my nose (by a few intervening lines of code that end up using the transit containers themselves).

So

Code: Select all

put it into myValue
put the result into tResult
if myValue = x .....
I think the OP is asking for the filename itself. I believe the user-selected file path is in "it", following the user not cancelling "answer file".

Code: Select all

if it is "Cancel" then
 exit to top -- exit the programme
else
 put it into tFileName
end if 
put "file:/" & tFileName into tURL
get URL tURL 

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: the variable "it"

Post by bn » Fri Dec 16, 2011 11:03 am

Hi Nigel,

additionally to what Jean-Marc and Bernard are saying:
do yourself a favor and do not use a reserved word (Livecode reserved word) for even naming of objects: filename is a reserved word. You could name your field "fFileName" or somesuch. It will not immediately break but is a recipe for trouble.

in your post you said
on mouseUp
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",fileName) into messageText
end mouseUp
the way you put it filename is just a litteral and you found out that Livecode treats it as that. It would be a variable name (except for the name conflict with the reserved word, see above) if you had put something into it. But apparently you wanted to reference the content of field "fileName". You would have to say

Code: Select all

on mouseUp
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",field "fileName") into messageText
end mouseUp
This is referencing the content correctly but if it breaks the quoting etc conventions of your database statement is beyond my expertise.

Kind regards

Bernd

NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

Re: the variable "it"

Post by NigelS » Fri Dec 16, 2011 11:22 am

Hi Bernard

Oops, screwed that one up. Thanks for pointing that one out.
I've changed the code as per your suggestion and the end result worked as I require.

The code ended up as such

on mouseUp
answer file "Please choose the INI file "
if the result is not "cancel" then
put it into field INIPathFileName
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",field "INIPathFileName") into messageText
end if
end mouseUp

Once again thanks for the input.
as a matter of interest, how do you get the code to display in the CODE: box?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: the variable "it"

Post by bn » Fri Dec 16, 2011 1:41 pm

Hi Nigel,
as a matter of interest, how do you get the code to display in the CODE: box?
if you mean the message box then just put

Code: Select all

on mouseUp
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",field "fileName") into messageText
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",field "fileName")
end mouseUp
This will put the GetINI() into messageText in the first line and the same into the message box in the second line

every put command without a destination puts things into the message box, often very handy.

Kind regards

Bernd

EDIT: I see now what you mean by CODE: box, got that wrong...
Last edited by bn on Fri Dec 16, 2011 2:52 pm, edited 1 time in total.

tjm167us
Posts: 50
Joined: Sat Dec 03, 2011 8:27 pm

Re: the variable "it"

Post by tjm167us » Fri Dec 16, 2011 2:34 pm

as a matter of interest, how do you get the code to display in the CODE: box?
Nigel, I think I understand what you mean: I had the same question the other day. When you want to reference code in this forum, press the "code" button right above the text field you type into and then copy your code in between the "[*code][/code*]" that is inserted for you (just like a quote).

Example:

Code: Select all

on mouseDown
put this into field that
end mouseDown
Hope that helps!
Tom

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

Re: the variable "it"

Post by Klaus » Fri Dec 16, 2011 2:45 pm

Or just paste/write the code, select it and then click "CODE"!

Come on guys, never worked with a text editor? 8)

NigelS
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 83
Joined: Sat Oct 22, 2011 2:37 pm

Re: the variable "it"

Post by NigelS » Fri Dec 16, 2011 3:34 pm

:oops: This is what happens when you've been in this bussines for many years. One is inclined to think you know it all until... then one makes a complete ass of oneself. :lol:

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

Re: the variable "it"

Post by Klaus » Fri Dec 16, 2011 4:24 pm

:D

Post Reply