Page 1 of 1
the variable "it"
Posted: Fri Dec 16, 2011 9:30 am
by NigelS
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.
Re: the variable "it"
Posted: Fri Dec 16, 2011 10:24 am
by jmburnod
Hi Nigels,
Sorry if i dont understand what you want (my english is in progress

)
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
Re: the variable "it"
Posted: Fri Dec 16, 2011 10:47 am
by NigelS
jmburnod wrote:Hi Nigels,
Sorry if i dont understand what you want (my english is in progress

)
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.

Re: the variable "it"
Posted: Fri Dec 16, 2011 10:52 am
by Bernard
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
Re: the variable "it"
Posted: Fri Dec 16, 2011 11:03 am
by bn
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
Re: the variable "it"
Posted: Fri Dec 16, 2011 11:22 am
by NigelS
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?
Re: the variable "it"
Posted: Fri Dec 16, 2011 1:41 pm
by bn
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...
Re: the variable "it"
Posted: Fri Dec 16, 2011 2:34 pm
by tjm167us
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
Re: the variable "it"
Posted: Fri Dec 16, 2011 2:45 pm
by Klaus
Or just paste/write the code, select it and then click "CODE"!
Come on guys, never worked with a text editor?

Re: the variable "it"
Posted: Fri Dec 16, 2011 3:34 pm
by NigelS

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.

Re: the variable "it"
Posted: Fri Dec 16, 2011 4:24 pm
by Klaus