Question Message box content based on boolean logic

Suhi100

New member
Joined
Jan 6, 2014
Messages
4
Location
London
Programming Experience
Beginner
Hello,

Can anyone help me out with this task please?

I have an If statement that consist of 2 parts so it looks like:

if value1 = this then
that
if value2 =this then
that

I would like to create a message box that has content based on the results of the If statement. So for example if result1 is 100 then the value 100 is displayed on the message-box in the first line but if its not 100 its not displayed. Similarly, if value2 is 100 then it is displayed on the message-box (in the first line or in the second depending if value1 is displayed at the same time) box if less it is not. There can be4 scenarios: both values displayed, value1 only,value2 only , none of them.

Should I use a function instead of the If statement?
Let me know if it is not clear enough

Thanks for your help!

Suhi
 
The MessageBox really has nothing to do with this. A MessageBox simply displays a String. How that String came to be is irrelevant to the MessageBox. This question is about how to construct a String based on two Boolean conditions.

Here's what I recommend and what I do myself in such cases. I create a List(Of String) and then, in each If block, I Add the appropriate String to the List. After the two If statements, I call String.Join to combine the contents of the List into a single String. If the List doesn't contain any items then that will produce an empty String; if the List contains one item then the result will be that item; if the List contains multiple Strings then they will be joined with the specified separator between each pair. You can then do whatever you like with that String, e.g. display it in a MessageBox. In your case, you might want to test for an empty String first because I'm guessing that you won't want to display that in a MessageBox.
 
Back
Top