NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Do While Expression Evaluation

Solved!
Go to solution

Do While
((

Val(Locals.DailySelfCalTimeMsgBoxInputHours)<0&& Val(Locals.DailySelfCalTimeMsgBoxInputHours)>23))||((Val(Locals.DailySelfCalTimeMsgBoxInputMinutes)<0&& Val(Locals.DailySelfCalTimeMsgBoxInputMinutes)>59))|| RunState.Sequence.Main["Message Popup"].Result.ButtonHit!="2"

msg Box to read in user input time
}

I have this logic, but the do while loop is never exited.  If I press the Cancel button, the do While loop is exited.  However, Locals.DailySelfCalTimeMsgBoxInputHours or Locals.DailySelfCalTimeMsgBoxInputMinutes meet the above conditions in the Do While expression, the loop still never exits.  As part of the Message Box Post Expression, I converted both the aforementioned string variables to numeric type and they display values as expected.  So, I am not sure why when I try to use Val(String) in the Do While expression, the evaluation does not work as intended.  Can someone shed any light on this problem?

0 Kudos
Message 1 of 8
(4,302 Views)

By the way ButtonHit is a number

Regards
Ray Farmer
0 Kudos
Message 2 of 8
(4,296 Views)

Ok, thanks.  However, the other logic other than the Button Hit does not work. Can the Val function be used the way I have listed it?

0 Kudos
Message 3 of 8
(4,288 Views)
Solution
Accepted by topic author kerugoya

Pseudo Code:

 

While

hours < 0 and hours > 23

    Or

minutes < 0 and minutes > 59

   Or

buttonhit <> 2

end while

 

OK. Hours will never be both negative and larger than 23. Minutes will never be both negative and greater than 59. buttonhit could be not 2. So, it looks like you will only ever get a true on buttonhit.

 

I think you either have you greater and less reversed, or you should replace your ANDs with ORs.

 

Good luck,

Bob Y.

0 Kudos
Message 4 of 8
(4,278 Views)

Yes, thanks for laying out the way you did.  I see my error.

However, I tried the following with hours having an input of anything less than 23, but the while loop is not exited.

do while { hours >23 or button hit !=2)
{
msg box

}

I am not sure what I am doing wrong. 

0 Kudos
Message 5 of 8
(4,275 Views)

Do While
(

Locals.DailySelfCalTimeMsgBoxInputHoursNumeric>23)||(RunState.Sequence.Main["Message Popup"].Result.ButtonHit!=2))
{

Msg Box}

Ok, the first condition Locals.DailySelfCalTimeMsgBoxInputHoursNumeric>23 by itself works and the same applies to the second condition.  However, when I put them in the OR condition, only hitting the Cancel Button, the second button, works.  The first condition somehow does not work.  Can someone please help?  I am not sure what I am missing here.

Thanks to everyone who have helped me so far.

0 Kudos
Message 6 of 8
(4,273 Views)

I don't really see any problems with the logic but I do see that you are missing one open parenthesis. I think you should be getting a compile error (unless it is just a typographical error in your post). Assuming that it gets placed with the other open parenthesis at the beginning of the logic expression, I don't see what would cause it to not trigger.

 

Sorry,

Bob Y.

0 Kudos
Message 7 of 8
(4,255 Views)

Thanks for the feedback.  There is a typographical error in my post.  An OR condition does not work for what I want to accomplish.  I managed to get it to work with an AND condition.  Thanks for your reply, though.

0 Kudos
Message 8 of 8
(4,251 Views)