I have tried all the brackets I can think of in the following
Latitude: <$edit-text tiddler="$:/TLS/latitude" tag="input" overwrite="yes"/>
<br> Format decimal, eg -33.1234
<p> or in <br>
Degrees: <$edit-text field="lathours" tag="input" overwrite="yes" size="6"/>
Minutes: <$edit-text field="latminutes" tag="input" overwrite="yes" size="6"/>
Seconds: <$edit-text field="latseconds" tag="input" overwrite="yes" size="6"/>
<$button set="$:/TSL/latitude" actions=<<DMS2DD {{!!lathours}} {{!!latminutes}} {{!!latseconds}}>> >
Convert
</$button>
The idea is that a user can type a set of coordinates as degrees, minutes and seconds and have the convert button convert to decimal format and put the result in $:/TLS/latitude
The procedure, DMS2DD works, I have tested it. Pass it three values and it returns their decimal equivalent to 2 decimal places.
I can not figure out how to achieve this. I have also tried putting the actions into an $action-setfield call but can not get this to work either.
The documentation on [[Calls|https://tiddlywiki.com/#Calls\]] implies that my call will not work as the parameters are not wikified. If this is true, how can I achieve what I am trying to do?
Any clues please
bobj
Several problems:
- You have a typo in the target tiddler’s title. The “Latitude”
$edit-text uses “$:/TLS/latitude”, but the DMS conversion button is using “$:/TSL/latitude”
- To use the
$button set=... syntax, you need to specify the value to save using a corresponding setTo=... param.
- Procedures do not “calculate and return”. Rather, they just output their contents, which are then “wikified” if rendered in a wikitext context, or are used “as-is” if passed along as a widget parameter value. In contrast, Functions can use filter syntax to actually calculate and return values based on their inputs.
- For your purposes, you can define
\function DMS2DD(d,m,s) that can be invoked using filter transclusion syntax (the tripled curly brackets) to actually calculate and return the desired value.
Give this a try:
\function DMS2DD(h,m,s) [<m>divide[60]] [<s>divide[3600]] +[sum[]trim[0]addprefix<h>fixed[4]]
Latitude: <$edit-text tiddler="$:/TLS/latitude" tag="input" overwrite="yes"/>
<br> Format decimal, eg -33.1234
<p> or in <br>
Degrees: <$edit-text field="lathours" tag="input" overwrite="yes" size="6"/>
Minutes: <$edit-text field="latminutes" tag="input" overwrite="yes" size="6"/>
Seconds: <$edit-text field="latseconds" tag="input" overwrite="yes" size="6"/>
<$button set="$:/TLS/latitude"
setTo={{{ [function[DMS2DD],{!!lathours},{!!latminutes},{!!latseconds}] }}}>
Convert
</$button>
Notes:
- The
DMS2DD function first converts the minutes and seconds to their equivalent decimal values.
- Next, it adds them together and trims off the leading “0” to retain only the decimal portion of the value
(i.e., .1234 instead of 0.1234)
- Then, it “glues” the hours value in front of the decimal minutes/seconds value
- Lastly, it rounds the final value to 4 decimal places
-e
Thanks @EricShulman worked but only after I put the function in my procedures tiddler and not in the text of the calling tiddler.
I am very new to TW functions. Do they go in the procedures tiddler or can they be anywhere?
bobj
Syntax that starts with \ (e.g., \define, \procedure, \function, \import, etc) are called “pragmas”, and must occur at the beginning of a tiddler, before any wikitext content. Alternatively, they can be placed in a separate tiddler that is tagged with $:/tags/Global.
- Pragmas that occur in a tiddler tagged with
$:/tags/Global can be referenced in any other tiddler
- Pragmas that occur at the beginning of a tiddler can be referenced anywhere within that tiddler
- Pragmas can also be “nested” within other pragmas. For example:
\procedure myProc(...)
\define something()
argle bargle
\end something
... myProc contents here ...
\end
Note in the above example that \end something includes the name of the nested pragma. This differentiates that \end from the \end of the containing pragma. Nested pragmas are “local” and can only be referenced within the containing pragma.
Note that \function definitions only use filter syntax and cannot use other wikitext syntax such as widgets.
refs:
https://tiddlywiki.com/#Pragmas
https://tiddlywiki.com/#Pragma%3A%20\procedure
https://tiddlywiki.com/#Pragma%3A%20\function
-e
However they can be written over multiple lines with a matching \end functionname. This is mostly useful for readability
Thanks @EricShulman I will study what you have suggested.
bobj