12-05-2011 02:51 PM
Hello, I have a homework assignment and I am facing few problems with the string indicator.
What I'm assigned is:
The user fills 2 arrays with 5 numbers
Then the user clicks on th FILL button and the program checks if the created elements in array 3 matches elements in array 1 and 2.
(I attached the doc file for clarity).
The string indicator gives wrong answers sometimes. (is there a better way to solve the string indicator?)
Thanks.
the vi is version 10.
Solved! Go to Solution.
12-05-2011 02:57 PM
You need to put your result string in a shift register in the For loop. As written the only value you get is the result of the last comparision. You need to update and add the result to the string (if necessary) every iteration of the For loop. A shift register will allow you to do this.
12-05-2011 03:32 PM
Yeah I noticed that.
I changed it but there is a problem with the enters.
Isn't there any better solution for such a problem?
I have changed the range from 0-2
12-05-2011 04:36 PM
Better is what way? Not placing the extra blank lines in the string? If that is the case you should only update the string when necessary, not every iteration of the loop. If you mean something else I don't know what you want to improve.
There are quite a few things that can be improved from a coding perspective. When you wire an array to a For loop it is best to use auto indexing to determine the number of iterations the loop will run. Barring that as in the case of your first loop you should use Array size to determine the number of iterations to run, not a constant value. Your second loop can be simplified and does not require the array. Use a shift register and negate the value of teh Boolean every iteration. Also, the logic in the thrid frame would be easier to understand if you used an Or rather than an And. If any value is True check the arrays. Your actually have reverse logic. While it is correct it is the opposite of what someone would be thinking. Another method would be to add the two results and wire the numberic value to the case structure. Case "0" means everything is acceptable. The Default case (anything not 0) means you have unacceptable values.
One last comment would be what is actually your stop condition? The two nested while loops looks rather strange and unnecessary.
12-06-2011 02:24 AM
Hi, I noticed the errors and changed them.
The loop stops when all numbers are acceptable; else it will comtinue when FILL is pressed.