VB.NET With…End With Statement: The With…End Statement and the structure of loop are different to each other. This statement helps in accessing and executing statements in particular objects without mentioning the name of objects together with the each statement. In a With Statement block, one can mention the object member beginning with period(.) for defining multiple statements.

The VB.NET With Statement do not have any new feature or function with respect to the other statements and keywords. It helps in improving the readability of code and also helps in the saving some precious time.

This statement is not completely like looping statements. In this, a complete series of statements referring an object or structure is executed at a single time.

  • The object that is referred in With statement is similar through the whole code in the With…End With block.
  • Thus, the properties and methods of the object is easily used in the code block without referencing the object.
  • If the inner With Statement directs to a sub object or dependent object of the outer With Statement, the With Statement becomes Nested.
  • An object member referred in a With Block omits object name and includes a period and a member name. 


objExpression: This helps in defining the DataType which could be a class or structure type or a basic data type like Integer. A single execution is allowed in With End With Statement.

Statement: Multiple statements can be defined in the With Block.Statement directs to the object member linked with objectExpression for the execution of With Statement Block.

End With: This is required in ending the With block.

Example: Write a program to understand the uses of With End With statement in VB.NET.



VB.NET With End With Statement

Example: Write a program to display the worker details using the With End statement in VB.NET.



VB.NET With End With Statement

Pin It on Pinterest

Share This