Hi,
I was wondering why when I declare the dim variable outside the try
statement, I could use the .dispose() function but when I declare it inside
the try statement, I get Name 'varname' is not declared.
thanks,
Will 4 2407
Will,
It has to do with variable scope.
If you use:
Dim x As IDisposable
Try
Finally
x.Dispose
End Try
The x variable is at the same scope as the Try itself.
However if you do:
Try
Dim y As IDisposable
Finally
y.Dispose
End Try
The y variable is in the Try's block scope.
Remember that most block statements in VB.NET introduces a new block scope,
allowing each scope to define the same variable.
For details on Scope in VB.NET see: http://msdn.microsoft.com/library/de...vbconScope.asp
Hope this helps
Jay
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl... Hi,
I was wondering why when I declare the dim variable outside the try statement, I could use the .dispose() function but when I declare it inside the try statement, I get Name 'varname' is not declared.
thanks, Will
wk6pack <wk***@sd61.bc.ca> wrote: I was wondering why when I declare the dim variable outside the try statement, I could use the .dispose() function but when I declare it inside the try statement, I get Name 'varname' is not declared.
Where are you trying to use it? In the finally block? If so, that's the
problem - the scope of the try block is just the try block, and with
good reason: the code execution might not have even reached the place
where your variable is declared before an exception is thrown.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
thanks for the explanation and reference.
Will
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Oi**************@TK2MSFTNGP11.phx.gbl... Will, It has to do with variable scope.
If you use:
Dim x As IDisposable Try Finally x.Dispose End Try
The x variable is at the same scope as the Try itself.
However if you do:
Try Dim y As IDisposable Finally y.Dispose End Try
The y variable is in the Try's block scope.
Remember that most block statements in VB.NET introduces a new block
scope, allowing each scope to define the same variable.
For details on Scope in VB.NET see:
http://msdn.microsoft.com/library/de...vbconScope.asp Hope this helps Jay
"wk6pack" <wk***@sd61.bc.ca> wrote in message news:uX**************@TK2MSFTNGP09.phx.gbl... Hi,
I was wondering why when I declare the dim variable outside the try statement, I could use the .dispose() function but when I declare it inside the try statement, I get Name 'varname' is not declared.
thanks, Will
yes, I was trying to use it in the finally block.
Will
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... wk6pack <wk***@sd61.bc.ca> wrote: I was wondering why when I declare the dim variable outside the try statement, I could use the .dispose() function but when I declare it
inside the try statement, I get Name 'varname' is not declared.
Where are you trying to use it? In the finally block? If so, that's the problem - the scope of the try block is just the try block, and with good reason: the code execution might not have even reached the place where your variable is declared before an exception is thrown.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: rick |
last post by:
Noob problem. I prefer to keep all my scripts in an external '.js' file.
I am currently loading the external '.js' file from the header. Problem is I
would like to declare
a global variable in the...
|
by: Simon Osborn |
last post by:
Hi,
Instead of adding my own custom dll's as references into my project, I want
to call it via declare statement. However, I'm having a few difficulties!
My dll contains a basic function :
...
|
by: Sakharam Phapale |
last post by:
Hi All,
How to declare the following statement in following structure.
szPname As String * MAXPNAMELEN
Public Structure MIXERCAPS
public wMid As Integer
public ...
|
by: wk6pack |
last post by:
Hi,
I was wondering why when I declare the dim variable outside the try
statement, I could use the .dispose() function but when I declare it inside
the try statement, I get Name 'varname' is not...
|
by: iwdu15 |
last post by:
hi, i need to have a declare statement for an API to call a method in it, the
only problem is that i dont neccessarily know where on the comp it will be. I
kno it will be in my application folder,...
|
by: John Bailo |
last post by:
I created a sproc with 3 input parameters and one output parameter.
I want to test it in the "Run SQL Scripts" app of Navigator.
I wrote this code:
DECLARE RTNDATE CHAR(10) DEFAULT '';
CALL...
|
by: juan.gautier |
last post by:
Hi,
I try to construct a SQL code for a view to select a specific data
from a table, this query take the value of the filter from a text box
in a visual basic 6.0 form. my problem is when i...
|
by: okonita |
last post by:
Hi all,
My environment is DB2 UDBv8.2 on Windows and Linux.
I am getting a lot of errors on the script you see below. Some of the error I am geting are:
...
|
by: Lennart |
last post by:
Any thoughts on the following scenario anyone?
During a performance test I discovered that the application asked one
specific query extremely often. It turned out that this particular
query...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |