By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,651 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

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

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

Such as:
Expand|Select|Wrap|Line Numbers
  1. Private Sub DoSomething(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Handles dvCertTypes.ListChanged, dvJobTypes.ListChanged
  2.         Dim _flw As FlowLayoutPanel
  3.  
  4.     If Equals(sender, dvCertTypes) Then _flw = flwCertTypes Else _
  5.             If Equals(sender, dvJobTypes) Then _flw = flwJobDesc Else _
  6.                 If Equals(sender, "both") Then LoadCertSelections(dvCertTypes, Nothing) : LoadCertSelections(dvJobTypes, Nothing) : Exit Sub
  7.  
  8.     Do more stuff...
  9. End Sub
  10.  
Jul 27 '10 #1

✓ answered by Joseph Martell

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
Expand|Select|Wrap|Line Numbers
  1. LoadCertSelections(dvJobTypes, Nothing)
will get executed before you exit your sub (assuming preceeding conditions are met).

Share this Question
Share on Google+
1 Reply


Joseph Martell
Expert 100+
P: 196
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
Expand|Select|Wrap|Line Numbers
  1. LoadCertSelections(dvJobTypes, Nothing)
will get executed before you exit your sub (assuming preceeding conditions are met).
Jul 27 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.