Usage of colon (i.e. : ) for multiple statements?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Infog
    New Member
    • Dec 2008
    • 36

    Usage of colon (i.e. : ) for multiple statements?

    When using : in VB.NET, will the order of events ALWAYS follow the order I've coded it in?

    Such as:
    Code:
    Private Sub DoSomething(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Handles dvCertTypes.ListChanged, dvJobTypes.ListChanged
            Dim _flw As FlowLayoutPanel
    
        If Equals(sender, dvCertTypes) Then _flw = flwCertTypes Else _
                If Equals(sender, dvJobTypes) Then _flw = flwJobDesc Else _
                    If Equals(sender, "both") Then LoadCertSelections(dvCertTypes, Nothing) : LoadCertSelections(dvJobTypes, Nothing) : Exit Sub
    
        Do more stuff...
    End Sub
  • Joseph Martell
    Recognized Expert New Member
    • Jan 2010
    • 198

    #2
    Basically yes, the order of execution should be effectively the same as written. Each statement separated by a : is treated as a separate statement and is subject to the same rules as statements on separate lines.

    Technically, there is no guarantee that statements are executed in exactly the same order as written in source. Remember that your source written in a .Net language goes through several compilations and optimizations before you end up with executable code.

    What you can guarantee is your sub will not be exited before valid preceeding statements are executed. In your example
    Code:
    LoadCertSelections(dvJobTypes, Nothing)
    will get executed before you exit your sub (assuming preceeding conditions are met).

    Comment

    Working...