Skip to content

Conversation

@JRAlexander
Copy link
Contributor

@JRAlexander JRAlexander commented Apr 13, 2018

If...Then...Else Statement (Visual Basic) API topic has repeated requests for updates. We'll update it, point to the relevant examples, and improve the experience.

Fixes #3505

URL for internal review

@JRAlexander
Copy link
Contributor Author

Closing and reopening - failed build

@JRAlexander JRAlexander reopened this Apr 13, 2018
Copy link
Contributor

@rpetrusha rpetrusha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a number of comments suggesting additional changes, @JRAlexander.


This article includes several examples that illustrate uses of the `If`...`Then`...`Else`statement:

* [Multiple-line syntax example](#multi-line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple-line --> Multiline


## Parts
`condition`
Required. Expression. Must evaluate to `True` or `False`, or to a data type that is implicitly convertible to `Boolean`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 65, there should be a space between Nullable and Boolean
if the expression is not True can be easily misread; much better to say "if the expression is `False`
no comma before "the `Else`"

Optional. One or more statements that are executed if no previous `condition` or `elseifcondition` expression evaluates to `True`.

`End If`
Terminates the `If`...`Then`...`Else` block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminates the multiline version of...




## Remarks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines 89 and 99 should be level-3 heads, not level-2
line 90: space between True and elseifcondition
line 97: several possible values --> more than three possible values
line 100 doesn't actually say what single-line syntax is: a single condition with code to execute if it's true


In the single-line syntax, you can have multiple statements executed as the result of an `If`...`Then` decision. All statements must be on the same line and be separated by colons.

## Example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Example header can't be deleted.

## Example
<a name="multi-line"></a>

The following example illustrates the use of the multiple-line syntax of the `If`...`Then`...`Else` statement.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple-line --> multiline


The following example illustrates the use of the multiple-line syntax of the `If`...`Then`...`Else` statement.

[!code-vb[VbVbalrStatements#101](../../../visual-basic/language-reference/error-messages/codesnippet/VisualBasic/if-then-else-statement_1.vb)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good here to make this executable -- so wrap it in:

Module Multiline
   Public Sub Main()

      Console.WriteLine(message)
   End Sub
End Module

Also, instead of "There are " & count & " items." --> $"There are {count} items." (to use an interpolated string)
And also show output


The following example contains nested `If`...`Then`...`Else` statements.

[!code-vb[VbVbalrStatements#102](../../../visual-basic/language-reference/error-messages/codesnippet/VisualBasic/if-then-else-statement_2.vb)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be good to wrap this in a Module...End Module statement, include a Main method so it's executable, and add output
The comments also aren't fully accurate. It doesn't test for 2 to 4 PM or noon to 1 PM, but from 2 to 3:59 and 12 to 12:59.

<a name="single-line"></a>
The following example illustrates the use of the single-line syntax.

[!code-vb[VbVbalrStatements#103](../../../visual-basic/language-reference/error-messages/codesnippet/VisualBasic/if-then-else-statement_3.vb)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here again, this could be a complete code example that's executable. You can use highlighting here (as well as in the other two examples) to focus on the If statements.

@JRAlexander
Copy link
Contributor Author

@rpetrusha I believe I've addressed all your comments. I'm having a bit of an issue with highlighting.

@rpetrusha
Copy link
Contributor

The problem with highlighting, @JRAlexander, is that the syntax is incorrect. Instead of
[!code-vb[VbVbalrStatements#101](../../../visual-basic/language-reference/error-messages/codesnippet/VisualBasic/if-then-else-statement_1.vb)]?highlight=10,12,14,16
try
`[!code-vbVbVbalrStatements#101], for example.

@JRAlexander
Copy link
Contributor Author

JRAlexander commented Apr 16, 2018

Got it! Thanks, @rpetrusha! Now I believe I've addressed everything!

Copy link
Contributor

@rpetrusha rpetrusha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, @JRAlexander. The one thing that's missing is output from the example, which can be commented-out at the end of the example. It's important to include them here, since the REPL isn't supported yet. Once you add them, you can merge.


## Quick links to example code

This article includes several examples that illustrate uses of the `If`...`Then`...`Else`statement:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space at the end before statement

If the expression is a [Nullable](../../../visual-basic/programming-guide/language-features/data-types/nullable-value-types.md) `Boolean` variable that evaluates to [Nothing](../../../visual-basic/language-reference/nothing.md), the condition is treated as if the expression is `False` and the `Else` block is executed.

`Then`
Required in the single-line syntax; optional in the multiple-line syntax.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't you change this to multiline?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that.


## Example

## Multiline Syntax Example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that you're completely revisiting the topic, I'd also fix the headings to be sentence case

@JRAlexander
Copy link
Contributor Author

Thank you, @rpetrusha and @mairaw, for your thoughtful comments!

@JRAlexander JRAlexander merged commit 725c2b4 into dotnet:master Apr 16, 2018
@JRAlexander JRAlexander deleted the vb-if-then-csat branch April 16, 2018 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Ref High traffic Low CSAT] If...Then...Else Statement (Visual Basic)

4 participants