05-01-2013 09:05 AM
Hello Everyone!
Just two short and probably dummy questions, hoping u would pls answer it and thx very much!
1. Is it really not good to set a shift register without initialization? What will be the result? Since I read fr many books and they all said it is better to initialize shift register whenever u set one.
2. Is there any case that we need the uninitialized shift register?
Best regards!
Solved! Go to Solution.
05-01-2013 09:14 AM
1) Each time you run a VI, the shift register begins with a value of 0. If you do not initialize the shift register, the loop uses the value written to the shift register when the loop last executed or, if the loop has never executed, the default value for the data type.
2) yes, we can use an uninitialzed shift register to preserve state information between subsequent executions of a VI.
05-01-2013 09:33 AM - edited 05-01-2013 02:29 PM
@sophiey wrote:
Since I read fr many books and they all said it is better to initialize shift register whenever u set one.
What kind of books are you reading??? 😮
The decision to initialize or not, depends on the desired functionality. There is no global "better" at all. It depends what you want to do.
Uninitialized shift registers (or globally initialized feedback nodes) provide the core functionality of action engines. One of the most useful programming tools. Get familiar with it and your skills will increase dramatically!
05-01-2013 02:20 PM
Thx, so it will not report the error such as "can not connect because of undefinition", I will learn it as fast as possible!
Also, sorry but the words that I learnt is from some chinese typical textbooks...
05-02-2013 01:33 AM
Hi Sophiey,
To initialise or not to initialise is the question. The guys were absolutely right.
If you want to start a loop (FOR or WHILE) with a new value, you want to initialise it.
If you want to use your VI as a FGLB (Functional global : stores data in stead of global variable or local var), don't initialise it. YOu want to use the previous data that was stored in the shift register when you last ran the VI.
05-02-2013 04:07 AM
Hi,
If the shift register is not initialized, the shift register is set to a default value when it is first loaded into memory. The default value depends on the data type of the shift register: an empty array for arrays, 0 for numeric types, and an empty string for strings.