문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top