01-24-2017 12:18 PM
Hey all, I'm currently trying to get better with LabVIEW and was reciently given the following task to test my skills:
1. Have a button on the screen that when clicked on will generate a random number between 1 and 100.
2. If the number is odd, display a message on the screen that lists the number and the string “Odd Number” next to it.
3. If the number is even, log the number to a text file by saving the number and the string “Even Number” next to it.
4. In either the odd or even case, if the user clicks the button to generate another random number, append the new number and string to the previous.
Currently I believe my code does what's needed and I think I've used all the best practicies/optomizations I'm aware of. However, I was wondering if there was anything I could do to improve on the code or anything I missed.
Solved! Go to Solution.
01-24-2017 01:54 PM
Wow it actually looks pretty decent and clean. Good work.
All the suggestions I have are pretty minor but since you are asking for suggestions here are mine, some are opinions and others could disagree.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
01-24-2017 02:10 PM
Hooovahh wrote:
- Arrays Constants Show Size
- Very minor, but I prefer array constants that show 1 more item than are in them so that at a glance you can tell that the number of items are the number you expect. In your Generate Value Change you have an array constant showing 2 items, but visually I couldn't tell you how many values are in that array.
I have gotten in the habit of showing the Scroll Bar with my array constants and get the same effect. Also easier to see if you are near the end of the array if you have a large one.
01-24-2017 02:17 PM
crossrulz wrote:I have gotten in the habit of showing the Scroll Bar with my array constants and get the same effect. Also easier to see if you are near the end of the array if you have a large one.
If there were a comment about array constants I didn't say, it would be that. In this case there are only two values so showing 3 elements seems fine to me. If there are 20 elements yeah I'll make the constant show some, maybe 5 and then have a vertical scroll bars showing anyone reviewing the code that it needs extra attention.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
01-24-2017 04:21 PM - edited 01-24-2017 04:26 PM
@Hooovahh wrote:
Wow it actually looks pretty decent and clean. Good work.
Thanks a lot, it's good to know that I'm better at this than I had thought I would be ^_^
Also, where did the "Discard?" boolean come from in the event structure? I've never seen that before.EDIT: NVM Found it
01-24-2017 04:28 PM
GentlemanS wrote:Also, where did the "Discard?" boolean come from in the event structure? I've never seen that before.
Well for others that stumble on this post. The event type is a filter event which is why it has the question mark in it. This means that the event to close the panel was requested, but the discard allows us to ignore the request to close the panel and do other things instead. The "Panel Close" event (without filtering) is fired when the panel is closed, and it has already closed with no option to discard the request to close. There are a few other filter events that are useful like Key Down? or Mouse Down? which can ignore presses.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
01-24-2017 04:51 PM - edited 01-24-2017 06:05 PM
A few more random points for the originally posted code:
01-24-2017 06:07 PM
Here's a quick rewrite showing some of my ideas. Check for bugs and modify as needed.
01-25-2017 07:23 AM
Sweet! I would have never thought of the bitwise and, I'm sure I'll use that in the future. A few questions though:
For this code, you combined the "Generate," and "Evaluate" cases. When we do that, should we go back to using a notifier instead of a queue structure? If not, when would one want to use a notifier?
01-25-2017 07:33 AM
GentlemanS wrote: If not, when would one want to use a notifier?
A Notifier is a lossy communication scheme. What this means is that a listener for the notification could miss one if the sender sends multiple before the reader can come back and check for the notification. So the general rule of thumb is that if you only care about the latest data being sent, use a Notifier. If you need to process every message, use a Queue.