From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Use filter events to implement string-only controls that accept numbers

Code and Documents

Attachment

Overview

Coding that exemplifies how to generate a string control that only allow numeric values.

 

Description

The filtered event is issued before LabVIEW handles the user action and waits for the corresponding event frame to complete. LabVIEW then processes the user action. There is a question mark after the name of such an event. For example, the keyboard press? Event (Key Down? Event), when the user to deal with the incident, the control value has not been changed, so the user can the event corresponding to the framework of the decision whether to allow LabVIEW to deal with the incident, or change the keyboard press Value and then let LabVIEW continue to process the event.


It is apparent that the filtering event is issued first than the corresponding notification event.


When there is more than one event structure on the block diagram of the same VI, the notification event is sent to all event structures at the same time, and the filter events are sent sequentially to each event structure. However, placing multiple event structures on the same VI is not necessary, and can easily lead to errors. You should avoid using multiple event structures on the same VI.

 

Requirements
LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code
1. Run the VI
2. Press any keys of the keyboard, and notice that only the numeric values are accepted
3. Press the Stop button to finalize the execution.

 

Additional Information or References

 Snippet.png

 

详细资料参考http://ruanqizhen.spaces.live.com/blog/cns!5852D4F797C53FB6!2004.entry

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
BetaCommunityCo
Member
Member
on

remove this from the site

this looks like spam !

BetaCommunityCo
Member
Member
on

chinese lv blog

This is actually a chinese lv blog. Looks a little spammy to the english community, but if you follow the link it's valid.

BetaCommunityCo
Member
Member
on

说明

过滤型事件是在 LabVIEW 处理用户操作之前发出的,并等待相对应的事件框架执行完成之后,LabVIEW 再处理该用户操作。这类事件的名称之后都有一个问号。例如键盘按下?事件(Key Down? Event),当用户处理该事件时,控件的值还没有被改变,因此,用户可以在该事件对应的事件框架内决定是否让 LabVIEW 先处理该事件,或改变键盘按下的值之后再让LabVIEW继续处理该事件。

可以明显地看出,过滤型事件比相应的通知型事件要先发出。

当同一VI的程序框图上有多于一个的事件结构时,通知型事件是同时被发往所有的事件结构的,而过滤型事件则是按顺序、依次发往每一个事件结构的。但是,在同一VI上放置多个事件结构是没有必要,而且极易引起错误的。所以应该避免在同一VI上使用多个事件结构。

Jason.Q
Member
Member
on

当非数字键被按住不放的时候,还是会被输入到字符串控件中,这个问题如何解决?