I'm having difficultly with the using statement in Visual Basic. Does anyone know how this should be written?:
Using (Dim doc As WordprocessingDocument = WordprocessingDocument.Open(filename, True))
//blah blah
End Using
The code works fine without the using and its obviously as syntactic error. "Dim" is highlighted, and an expression is expected apparently. Sorry if this a bit basic, but the info on vb using statements is not clear and its obviously doesn't work in the c# style.
A statement in Visual Basic is a complete instruction. It can contain keywords, operators, variables, constants, and expressions. Each statement belongs to one of the following categories: Declaration Statements, which name a variable, constant, or procedure, and can also specify a data type.
The using statement causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the object is read-only and can't be modified or reassigned. A variable declared with a using declaration is read-only.
Conditional statements are used to perform different actions for different decisions. In VBScript we have four conditional statements: If statement - executes a set of code when a condition is true. If...Then... Else statement - select one of two sets of lines to execute.
By using With... End With , you can perform a series of statements on a specified object without specifying the name of the object multiple times. Within a With statement block, you can specify a member of the object starting with a period, as if the With statement object preceded it.
There's two things wrong.
First, you must remove the Dim
keyword. The Using
keyword replaces the Dim
keyword. Both Dim
and Using
have the same effect of declaring a new variable, just in different ways.
Secondly, you must remove parentheses. The very first thing after the Using
keyword must be the variable name.
Using doc As WordprocessingDocument = WordprocessingDocument.Open(filename, True)
' blah blah
End Using
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With