Qizhen's profileLabVIEWPhotosBlogListsMore Tools Help

Blog


    美化程序 - 隐藏程序框图上的大个 Cluster

     
        在编写某些程序的时候可能会遇到如图1 所示的情形:即用到了一个极为复杂的数据类型常量。 这个常量由于体积巨大,使得在程序框图无论怎么摆放都让人看起来不太舒服。如何才能把这个程序改造得美观一些呢?

    图1:体积巨大的常量会有碍观瞻

     
       要解决这个问题,只有设法把这个常量在主程序框图上隐藏起来。通常可以用以下两种方法。
        第一种方法:把这个常数变换成控件,再把控件隐藏起来。这种方法比较简单,但是也有弊病。①容易引起误解:控件一般表示有值传入,其他人读程序读到这里就可能搞不清楚这个值是从哪里传来的了;②如果要修改常量 Cluster 中某一个元素的值,操作起来比较麻烦。
     
        第二种方法,也就是我向大家推荐的:把它隐藏到更深层的子 VI 中去。具体操作方法如下:
     
        如图2 先给这个复杂数据类型建立一个 Strict Type Def。我的建议是为所有程序中用到的 Cluster 都建立一个 Strict Type Def。这样可以为以后的程序维护省去很多麻烦。

    图2:Strict Type Def.

     
        然后然后再建立一个新的 VI,把我们要隐藏的这个个头巨大的常量摆放在这个 VI 中,并且连接一个 Indicator ,以把它的值传出来。VI 的接线板采用 4-2-2-4 格式的,最下层第 3 个接线端用于传出 VI 中唯一的数据,如图3 所示。

    图3:用于隐藏个头巨大常量的 VI

        这个 VI 的图标要做得小巧漂亮,如图4,图标不一定非要做成正方形。只要 B&W 和 256 Colors 中的图标形状一样,我们就可以画出不规则图标了。详细方法可以参考《制作不规则图形的子VI图标》

    图4:常量数据 VI 的图标

     
        把这个新造出来的常量数据 VI 拖到程序框图上,把它的输出链接到刚才链接常量的地方,再把位置摆放好。现在我们的程序是不是漂亮多了

    图5:改造后的程序框图

     
     
     相关文章:
     

     
     
     

    Comments (8)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    刘伟印wrote:
    不错,有意思,呵呵
    Aug. 25
    No namewrote:
    谢谢大侠 
    Aug. 13
    捷周wrote:
    不错,多谢分享!!!
    Jan. 3
    Qizhen Ruanwrote:
    写 LabVIEW 程序一定要养成把代码整理干净漂亮的习惯。这样在每次构造一个新的 Cluster 类型,自然而然就会采用以上的方法,不会觉得有太多麻烦。这样却为以后的维护省去了几倍的时间。
    关于 Type Def. 和 Strict Type Def. 过几天讨论 :)
    July 31
    Yongqing Yewrote:
    这个方法我已经被阮大侠教育过了,还是不错的!
    July 31
    Jing Panwrote:
    好是挺好,就是麻烦了点。
    July 30
    来来wrote:
    路过,欢迎来访
    July 29
    来来wrote:
    路过,欢迎来访
    July 29

    Trackbacks

    The trackback URL for this entry is:
    http://ruanqizhen.spaces.live.com/blog/cns!5852D4F797C53FB6!1521.trak
    Weblogs that reference this entry
    • None