學(xué)習(xí)LabVIEW(三)——觀念的轉(zhuǎn)變

明明已經(jīng)用Add添加了Key: "eleven",為什么有時(shí)候會(huì)查詢失敗呢?原因在于我們使用了錯(cuò)誤的觀念編寫LabVIEW程序。

看起來,從左到右執(zhí)行的話,似乎Add是先于TryGetValue的。這實(shí)際上是圖形的繪制方式迷惑了我們。如果簡(jiǎn)單調(diào)整一下各個(gè)節(jié)點(diǎn)的位置,如下圖所示:

以數(shù)據(jù)流動(dòng)為核心的LabVIEW就不一定會(huì)先執(zhí)行哪一個(gè)函數(shù)了。如果先執(zhí)行的是TryGetValue,就會(huì)出現(xiàn)查詢失敗的情況。

用這個(gè)平鋪式順序結(jié)構(gòu)將需要先于TryGetValue調(diào)用的部分框起來,如下圖所示:

這樣一來,只有框內(nèi)所有的動(dòng)作執(zhí)行完成之后,數(shù)據(jù)才會(huì)繼續(xù)往下流動(dòng),于是再也沒有出現(xiàn)查詢失敗的情況了。
評(píng)論