the variable "it"
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
the variable "it"
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.
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"
Hi Nigels,
Sorry if i dont understand what you want (my english is in progress
)
if you want the content of the file
Best regards
Jean-Marc
Sorry if i dont understand what you want (my english is in progress

Yes, it = empty after the end of the handlerwhen doing the put into the field fileName, it remains blank
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
Jean-Marc
https://alternatic.ch
Re: the variable "it"
jmburnod wrote:Hi Nigels,
Sorry if i dont understand what you want (my english is in progress)
Yes, it = empty after the end of the handlerwhen doing the put into the field fileName, it remains blank
if you want the content of the fileBest regardsCode: 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
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"
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
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".
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 .....
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"
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 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
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
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 sayon mouseUp
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",fileName) into messageText
end mouseUp
Code: Select all
on mouseUp
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",field "fileName") into messageText
end mouseUp
Kind regards
Bernd
Re: the variable "it"
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?
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"
Hi Nigel,
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...
if you mean the message box then just putas a matter of interest, how do you get the code to display in the CODE: box?
Code: Select all
on mouseUp
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",field "fileName") into messageText
put GetINI("[MESSAGEDIR]","[ENDMESSAGEDIR]","MessageBookDir"," ",field "fileName")
end mouseUp
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.
Re: the variable "it"
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).as a matter of interest, how do you get the code to display in the CODE: box?
Example:
Code: Select all
on mouseDown
put this into field that
end mouseDown
Tom
Re: the variable "it"
Or just paste/write the code, select it and then click "CODE"!
Come on guys, never worked with a text editor?
Come on guys, never worked with a text editor?

Re: the variable "it"

