send command and comma in parameter
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
send command and comma in parameter
Dear colleagues,
I am new in the LiveCode universe, please forgive me, but found a problem I don't know how to handle.
I wrote a simple command "LoadFromFile" which accepts a valid file name in an image control.
When I like to use it inside a Button onMouseup handler and have to call it outside of the normal message path, I learned to use the send command.
But curiously the send command accepts a string. Therefore we have to write:
send "LoadFromFile " & tFileName to image "foo"
But sometimes filenames contains commas and maybe other funny characters, e.g. "my,best,image.jpg" is a valid filename!
Now as my LoadFromFile command accepts only one parameter, it sees only the front part of the file name (in the previous sampe "my").
How do I prevent this?
Do I really have to send custom command names and their parameters as strings???
Do I have to escape special characters in strings which have a special meaning in the LiveCode language?
Thank you in advance,
Thomas
I am new in the LiveCode universe, please forgive me, but found a problem I don't know how to handle.
I wrote a simple command "LoadFromFile" which accepts a valid file name in an image control.
When I like to use it inside a Button onMouseup handler and have to call it outside of the normal message path, I learned to use the send command.
But curiously the send command accepts a string. Therefore we have to write:
send "LoadFromFile " & tFileName to image "foo"
But sometimes filenames contains commas and maybe other funny characters, e.g. "my,best,image.jpg" is a valid filename!
Now as my LoadFromFile command accepts only one parameter, it sees only the front part of the file name (in the previous sampe "my").
How do I prevent this?
Do I really have to send custom command names and their parameters as strings???
Do I have to escape special characters in strings which have a special meaning in the LiveCode language?
Thank you in advance,
Thomas
Re: send command and comma in parameter
Thomas...
You could do something like this... say, in the script of a button
then say in the card script...
and then in this example... myStangelyFormatted, fileName.jpg ... will be returned in the msg box.
Dixie
You could do something like this... say, in the script of a button
Code: Select all
on mouseUp
put "myStangelyFormatted, fileName.jpg" into theFile
loadFromFile theFile
end mouseUp
Code: Select all
on loadFromFile theFile
put theFile
end loadFromFile
Dixie
Re: send command and comma in parameter
Dear Dixie,
thank for you answer. But calling a command in the message path is not really a problem.
But my command is not in the message path. It is in another control.
Therefore I have to use "send".
In my button script
In my image script
and here the message box shows only "myStangelyFormatted".
Do you have a solution for this?
Thank you in advance.
Regards, Thomas
thank for you answer. But calling a command in the message path is not really a problem.
But my command is not in the message path. It is in another control.
Therefore I have to use "send".
In my button script
Code: Select all
on mouseUp
put "myStangelyFormatted, fileName.jpg" into theFile
send "loadFromFile " & theFile to image "myImg"
end mouseUp
Code: Select all
on loadFromFile theFile
put theFile
end loadFromFile
Do you have a solution for this?
Thank you in advance.
Regards, Thomas
Re: send command and comma in parameter
Thomas...
Have a look at the 'dispatch' command in the dictionary... I think that this will be your friend in this case.
A quick example... let's say in the script of a button on card 1
and then in the card or stack script
any help...?
Dixie
Have a look at the 'dispatch' command in the dictionary... I think that this will be your friend in this case.
A quick example... let's say in the script of a button on card 1
Code: Select all
on mouseUp
put "boo" into tData
dispatch "updateField" with tData
end mouseUp
Code: Select all
on updateField tdata
put tdata into fld 1 of card 2
end updateField
Dixie
Re: send command and comma in parameter
Dear Dixie,
I tried
and this works now!!!
Thank you very much for your help.
Have a nice day.
Best regards,
Thomas
I tried
Code: Select all
on mouseUp
put "myStangelyFormatted, fileName.jpg" into theFile
dispatch "loadFromFile" to image "myImg" with theFile
end mouseUp
Thank you very much for your help.
Have a nice day.
Best regards,
Thomas
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: send command and comma in parameter
Extra bonus points: not only is the syntax for passing arguments with "dispatch" slightly simpler than with "send", but in terms of execution speed "dispatch" performs measurably faster (not enough to be noticeable, but if you need to use such things frequently it can add up).
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