對於學習Ui-Path的新手,可能會需要知道這個,所以這篇文章給學習Ui-Path的新手一個參考。
Ui-Path 語法:Ui-Path 中的Operator的 And 與 AndAlso
Ui-path借用了VB.Net的語法: And 與 AndAlso
JAVA則是 & 與 && ,分別代表 And 與 AndAlso。
And表示判斷在And前面的判斷式如果是False仍會再去判斷And後面的判斷式是否為Truth。
AndAlso則表示如果AndAlso前面的判斷式如果已經為False,則不需要再去判斷後面的判斷式是否為Truth,因為整條判斷式已經為False,所以一定會走False的那條路線,不需要再去判斷AndAlso後面的判斷式,如此可以省一點CPU的時間。
|
如上圖,num2=and後面的判斷式,因為s_empty是空的,如果對沒有宣告的變數操作,會拋出nullpointerException,所以表示有去判斷後面的判斷式。
|
錯誤訊息如下:
Source: If
Message: Object reference not set to an instance of an object.
Exception Type: System.NullReferenceException
RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object. at lambda_method(Closure , ActivityContext ) at Microsoft.VisualBasic.Activities.VisualBasicValue`1.Execute(CodeActivityContext context) at System.Activities.CodeActivity`1.InternalExecuteInResolutionContext(CodeActivityContext context) at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity`1 expressionActivity) at System.Activities.InArgument`1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor) at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath) at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary`2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary`2 argumentValueOverrides, Location resultLocation, Int32 startIndex) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
|
而如果使用AndAlso則不會有錯誤,如下圖,把and改為andAlso之後執行程式:
上面程式輸出如下:
test_001 execution started falsetest_001 execution ended in: 00:00:00
|
沒有錯誤訊息,表示AndAlso後面的判斷式沒有被執行,所以不會拋出錯誤訊息。
Or 與 OrElse 也是這樣,如果在OrElse前面的判斷式為True則走True路線,不需要再判斷OrElse後面的判斷式。
that's it.
留言
張貼留言