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 2469
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******** ******@TK2MSFTN GP09.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.co m> 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******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP09.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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... 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.co m> 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 external file, but I keep getting an error about
the object does not exist.
Can someone tell me where or how to declare a global variable in an external
file that is
available after the page is loaded.
|
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 :
Public Class MyDLL
Public shared function MyTestFunction (byval mystr as string)
try
|
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 wPid As Integer
public vDriverVersion As Long
|
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 declared.
thanks,
Will
|
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, but how do i say that in the
declares statement? for instance, i have this
Private Declare Sub AccCreateSession Lib "acccore.dll" Alias "#111" _
(<MarshalAs(UnmanagedType.LPStruct)ByVal Name As Guid,
<MarshalAs(UnmanagedType.IDispatch)ByRef...
| |
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 MANLIB.MANDATCL('ADD','20060101','1',RTNDATE)
SELECT MYVAR;
|
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 DECLARE the variable
@AMP receive a error message that said "The Declare cursor SQL
construct or statement is not supported." What i do wrong? Please help
me. i attach the code.
DECLARE @AMP int;
|
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:
-----------------------------------Start of Script-----------------------------------
---------------------original creation by Norm Wong------------------------
CREATE PROCEDURE DB2ADMIN.REORGTS( )
DYNAMIC RESULT SETS 1
|
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 where asked 25/50/100 or 200 times from a "htmlpage", dependent
of user preferences. I figured that using a global temp table, looping
and inserting, then join would do the trick.
However, it turned out that this killed performance totally. Why,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |