In your "pasted" version you don't have quotes, but in your field example, you do have quotes around the number.
I'm assuming this is a calculation:
calcfield = "var sizescaled = " & table:field
That's all you should need if the var you are setting is a number (any precision). You don't say what the rest of the calculation is (if any), so this may or may not be correct.
thanks for your reply
There is no other calculation involved, its simply to fetch the fm fields value which I pass to other parts of my script.
I have added a snip of the script which might show what I am trying to do.
the highlighted areas are fields that are working properly and doing exactly what I want.
the red areas show the var and where I am using the it
When you are inserting the value of a FileMaker field, you are ending the quote environment, concatenating the field value, and then concatenating a new quote environment.
In your snip I think the first circled item should be
var drawscale = " & Cad::drawScale & ";
The first quote in the line above is ending a quote in a FileMaker expression that spanned many previous lines (with the opening quote not visible in your snip). The second quote starts a new filemaker quote string that spans multiple lines that follow it.
var drawscale = \"" & Cad::drawScale & "\";
No, if the calculation is calling the field ALL OTHER bits need to be quoted, but the field does not.
var drawscale = " <<-- note the END of the text at this point so a field's value can be inserted
& Cad::drawScale &
" <<--- end of text as double quote
" <<--- end of text as double-quote
Please describe in more detail how this is being used.
now I am totally confused
why when I manually place a value in the code instead of a fm field all works ok?
reason for asking is that if you look at rectangles being drawn , the width and height are referenced fm fields, should they just be & table::field & and if so why does it work?
I am using a webviewer to display drawn objects on canvases
The "reference" to another field within a text field will not be "evaluated". If the field is a calculation type field, it can be evaluated.
You are trying to create "code" that is just text, but supplied with values from other field(s).
Putting the code inside a "web viewer" is like putting it inside a calculation dialog, and it's evaluated. But the text has quotes and the references to the other fields do not.
Some notes and suggestions that (hopefully) will do away with your confusion and help you write your code more easily:
1. You're essentially building a string; that this happens to be valid code in another environment is beside the point; the usual rules of string-building in FileMaker apply.
2. If you quote a field reference, or place it inside a string, FileMaker cannot evaluate it; it's just a part of a 'dumb' string.
3. Numbers that are passed as numeric arguments should not be quoted; AFAIK, this holds true for all (modern) programming environments.
5. Use the Let() function; this will optimize the code for both you (better readable, depending on your variable names) and FileMaker (fewer field accesses). Win-win, as they say …
6. For trouble-shooting, calculate your code in a field and reference that field in your Web Viewer. Place the field on the layout to see the calculated HTML; this should help to spot obvious errors.
See attached file for a number of ways to combine string literals and field (or variable) references.
thanks for all your help
just looked at your demo! think I should have done a bit of research before I started,
I can see already even with little experience that I can achieve results.
I rebuilt my calculation as you recommended and I have to say I learnt alot and have a better understanding on how to progress.
Unfortunately the problem with the decimal and the scale function is still lurking!
I set the variable for scale in the let function drawscale = table::field it doesnt work
If I set the variable in the let with the value of the field ie drawscale = "0.678989878789" this works!
In the field you recomended me to add to my layout I noticed that when drawscale =table::field is used
that a coma instead of a fullstop is between the 2 values in the scale function.
I have added a snip of the field for a visual. the second snip is the the var set as a fixed value in the let and it works ok but I cant help but notice a coma in the first value.
Why don't you post your file?
From those snippets, which show the end result of a calculation, not the calcuation itself, it's hard to tell what causes the difference; and I have no idea of the values in your fields or the calculations you perform to get these compound values.
I have not seen the demos posted here. But another method is to use a text field and "placeholders":
var x = 'abc';
var y = 123;
var z = <<field1>>;
Sorry but I dont fully understand
going to build a small version for testing purposes and will post it up here if I havent had any success solving the problem in between times.