LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use global Variable for Formatstring

Hello

I wanna use a global variable for a format string. see picture. But I don't work.
Can anybody give me an idea, why it won't work?
Thanks a lot!!!
0 Kudos
Message 1 of 8
(3,009 Views)
Sebastian,

The problem is not your format string. Your wire is broken because the cluster that was built does not match the type of the cluster in the array your are building. Try wiring the dummy cluster into the cluster input (middle terminal) of your "Build cluster" node and you will see the bundle change its inputs to the correct number and type.

Good luck,

-Jim
0 Kudos
Message 2 of 8
(3,009 Views)
I don't think you can use a global as a format string. Wiring a global makes the Scan from String default to all DBL outputs and I don't see any way around that since that until the VI is run, the contents of the global is not known so the data types won't match and you'll have a broken VI which you can't run. Catch-22.
0 Kudos
Message 3 of 8
(3,009 Views)
Format strings don't have to come from constants. They can be programatically defined in a variety of ways. However, if not defined by a constant or by default values, the Scan from String outputs become polymorphic (defined by backwards type propogation from a non-polymorphic input). Unfortunatly, as you have made me realize, Dennis; bundle elements (even with a defined cluster type) are considered by this algorithm to be polymorphic (I guess), therfore they cannot propogate their type upstream.

So the correct answer is to wire up the default values for the non-DBL elements in the Scan from String.

Attached is an example image.

-Jim
0 Kudos
Message 4 of 8
(3,009 Views)
Well, problem number one is that of the global is supposed to have in it the same value that's in the constant on the diagram, the value in the global is incorrect. The last format string is the constant is "%s" for a string. The string output doesn't appear in the "Scan from String" outputs. Therefore the format string in the global can't be the same as the one in the constant.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 8
(3,009 Views)
Never mind... just tried it after reading Jim's second post and he's right. I can see why someone might want to change the scan string on the fly, too bad it doesn't work.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 8
(3,009 Views)
It does work, Mike. You just have to define the output element types of Scan from String using the default value inputs.

-Jim
0 Kudos
Message 7 of 8
(3,009 Views)
As others said, the problem is not the global.

See attached a picture of how to do what you want. Since the Format String is unknown at edit time, you must provide the types to all inputs that are not DBL.

From your example, the while loop has been coded exactly like a for loop. It can be replaced with a for loop with auto-indexing, unless you really want the local variable to be update at each iteration every 50 ms. This delay is not necessary unless the computed array is huge and you want to leave some CPU time to other code in your application. Even then you can enter a delay of 0ms to force to swap to other tasks.

I don't know what your INT>BOOL VI does but using Scan from String you can read a number directly into a boolean. The number i
s rounded to an unsigned integer and 0 is False and >0 is True.

For example you scan a string for a boolean with format string %d.
"0" --> False
"24" --> True
"-18" -- False (coerced to unsigned = 0)

You scan a string for a boolean with format string %f:
Negative number up to "0.5" --> False (coerced and rounded to 0)
Number greater that 0.5 --> True


LabVIEW, C'est LabVIEW

0 Kudos
Message 8 of 8
(3,009 Views)