*variable_to_script Function
Syntax
Arguments
- Result
Xbasic script to re-create variables that were inside the passed frame/pointer
- varFrame
pointer variable
- options
(optional) w : Generate with statements
(optional) q : Use quotes for long strings (not <<%str%...%str%) (build 9276 or above)
- stringTagMap
(optional) Control string tag names
Description
Create a script that would initialized the variables in the variable frame - option flag 'w' - generate with statements.
Discussion
Create an Xbasic script to re-create the variables in the passed variable frame (pointer variable).
Example
The function takes a dot variable and serializes it as an Xbasic script. The dot variable can be reconstituted by executing the generated script. Contrast this with property_to_string() and property_to_blob(), which also serialize a dot variable.
dim p as p p.name = "alpha" p.city = "boston" ?*variable_to_script(p) = DIM name as C = "alpha" DIM city as C = "boston" dim p2 as p p2.name = "alpha" dim p2.array[2] as p p2.array[1].prop1 = "prop1" p2.array[1].prop2 = "prop2" p2.array[2].prop1 = "prop3" p2.array[2].prop2 = "prop4" ?*variable_to_script(p2) = DIM name as C = "alpha" DIM array[2] as P DIM array[1].prop1 as C = "prop1" DIM array[1].prop2 as C = "prop2" DIM array[2].prop1 as C = "prop3" DIM array[2].prop2 as C = "prop4" 'using the 'w' flag you get cleaner, easier to read code ?*variable_to_script(p2,"w") = DIM name as C = "alpha" DIM array[2] as P with array[1] .prop1 = "prop1" .prop2 = "prop2" end with with array[2] .prop1 = "prop3" .prop2 = "prop4" end with p3.colors = comma_to_crlf("alpha,beta,gamma") p3.html = "this is some html" + crlf() + "second line" ?*variable_to_script(p3) = DIM colors as C = <<%str% alpha beta gamma%str% DIM html as C = <<%str% this is some html second line%str% 'in the above example, a5 chose to use 'str' as the long string delimiter. 'By passing in a map (of property name to string delimiter), ' you can specify what delimiter to use for various property names ' Notice that the .html property is now delimited using %html%, ' not %str% as in the above example ?*variable_to_script(p3,"",comma_to_crlf("*html*|%html%,*Xbasic*|%code%,*serverside*|%code%")) = DIM colors as C = <<%str% alpha beta gamma%str% DIM html as C = <<%html% this is some html second line%html%
See Also