07-16-2010 03:28 AM
Has anyone looked at the example 'Only allow alphanumeric keys' on the Example Programs section of the NI website (posted 5th May 2010)?
http://decibel.ni.com/content/docs/DOC-10378
My question is, how does this particular program differentiate the regular keys, from the none regular? Ive stepped through it numerous times now with the lightbulb on, and still fail to see how it will happily pass a Z, but not F1 or space, for example.
Regards,
Craig
Solved! Go to Solution.
07-16-2010 03:34 AM
I can't open the VI since I don't have LV2009 on this machine.
My guess is that the array indexed in the FOR loop is a list of valid characters, and the "Pressed" keys array is checked vs. every element of it
Marco
07-16-2010 03:36 AM
On the left side of the for loop there are two arrays. The first array is empty and used to initialize the shift register.
The second array has all the allowed keys. That's the crucial bit. It only shows the first element, but it has more elements.
The loop goes over each element in that array and checks if it's in the keys which have been pressed. If it is, it adds it to the top array.
Personally, I would probably implement something like this using an event structure with the Key Down? event, but that depends on the actual requirements.
07-16-2010 03:47 AM
I did look in the second array, and it has all of the keyboard key options in it, which was why I'm struggling.
Its only out of curiosity, as looking through the forums for alphanumeric ive found some very suitable alternative examples for my project using regex (I learn something new every day).
07-16-2010 04:32 AM - edited 07-16-2010 04:34 AM
@micronfab wrote:
I did look in the second array, and it has all of the keyboard key options in it
No, it doesn't. The enum has all these values, but the array does not use all of them - it has 36 elements, which are 0 through 9 and A through Z.
You can see this more clearly if you resize the array constant. Hover over its bottom border until you get the resize handle, then click and drag downwards. You can also use the index display to go to the last element of the array (35).
07-16-2010 05:37 AM
@micronfab wrote:
[...] found some very suitable alternative examples for my project using regex (I learn something new every day).
This was my first thought when I read your original post
.
07-16-2010 05:44 AM
Thank you to everyone who replied. I now understand how the particular program works, though as I'm in my first year of programming Labview there is no way I could re-create it! Its easier for me to just borrow code as and where I can, and hopefully gain an understanding as I go along.
Regards.