Everyone knows that global variables get re-set in an mdb when an un-handled
error is encountered, but it seems that this also happens when the variable
is defined as private at form-level.
So if "global variables get re-set" doesn't tell the whole story, then what
does?
***please note***
I'm not looking for a solution - I'm looking for a more detailed description
of what happens when an un-handled error occurs - possibly with help file or
website reference.
Example:
Three buttons on a form, press them 1,2,3 (which causes an un-handled error)
then back to 2. m_strCode is re-set.
Private m_strCode As String
Private Sub cmdOne_Click()
m_strCode = "A1"
End Sub
Private Sub cmdTwo_Click()
MsgBox m_strCode
End Sub
Private Sub cmdThree_Click( )
MsgBox CStr(1 / 0)
End Sub 21 4414
"Anthony England" <ae******@oops. co.uk> wrote in
news:dl******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com: Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level.
So if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a more detailed description of what happens when an un-handled error occurs - possibly with help file or website reference.
Example: Three buttons on a form, press them 1,2,3 (which causes an un-handled error) then back to 2. m_strCode is re-set.
Private m_strCode As String
Private Sub cmdOne_Click() m_strCode = "A1" End Sub
Private Sub cmdTwo_Click() MsgBox m_strCode End Sub
Private Sub cmdThree_Click( ) MsgBox CStr(1 / 0) End Sub
Change the private module-level variable either to a function or a
custom property:
Private Function strCode() As String
Static strCodeStatic As String
If Len(strCodeStat ic) = 0 Then
strCodeStatic = "A1"
End If
strCode = strCodeStatic
End Function
OR:
Private Property Get strCode() As String
Static strCodeStatic As String
If Len(strCodeStat ic) = 0 Then
strCodeStatic = "A1"
End If
strCode = strCodeStatic
End Property
I'm not sure that there's any advantage to one or the other.
The key here is that the value is set to a static variable internal
to your function/property, and if the code has been reset, the
static variable is re-assigned transparently.
The advice I've given about avoiding global variables applies to
module-level variables, too.
--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
"David W. Fenton" <dX********@bwa y.net.invalid> wrote in message
news:Xn******** *************** ***********@216 .196.97.142... "Anthony England" <ae******@oops. co.uk> wrote in news:dl******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level.
So if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a more detailed description of what happens when an un-handled error occurs - possibly with help file or website reference.
Example: Three buttons on a form, press them 1,2,3 (which causes an un-handled error) then back to 2. m_strCode is re-set.
Private m_strCode As String
Private Sub cmdOne_Click() m_strCode = "A1" End Sub
Private Sub cmdTwo_Click() MsgBox m_strCode End Sub
Private Sub cmdThree_Click( ) MsgBox CStr(1 / 0) End Sub
Change the private module-level variable either to a function or a custom property:
Private Function strCode() As String Static strCodeStatic As String
If Len(strCodeStat ic) = 0 Then strCodeStatic = "A1" End If strCode = strCodeStatic End Function
OR:
Private Property Get strCode() As String Static strCodeStatic As String
If Len(strCodeStat ic) = 0 Then strCodeStatic = "A1" End If strCode = strCodeStatic End Property
I'm not sure that there's any advantage to one or the other.
The key here is that the value is set to a static variable internal to your function/property, and if the code has been reset, the static variable is re-assigned transparently.
The advice I've given about avoiding global variables applies to module-level variables, too.
-- David W. Fenton http://www.bway.net/~dfenton dfenton at bway dot net http://www.bway.net/~dfassoc
Thanks for that, David. As I mentioned, it's not really a workaround I'm
looking for as I do have a stratgegy to avoid this. It's more a question of
trying to concisely state what happens when an un-handled error occurs.
Previously, I would have said "... global variables (those defined as public
in an external module) get re-set". Now I might amend that to "...
variables defined as public in modules plus those defined at form level get
re-set"
However, that's not that concise and may not be the end of the story. Could
there be any other bits that have escaped my attention? Does anyone want to
try to complete the following sentence clearly and concisely:
When an un-handled error occurs....
> So if "global variables get re-set" doesn't tell the whole story, then what does?
The whole storey:
A unhandled error will reset variables (end of story). (that is it,
nothing more, nothing less).
It does not matter if the variable is local to a form, global to a module,
private or whatever. In plain English, a un-handled error re-sets variables.
That is it...done, all variables get re-set. There is no "thinking" here,
but things are simply re-set.
***please note*** I'm not looking for a solution -
Actually, there is a simply catch all solution. Just distribute a mde to
your users. All errors now, even when you don't trap them will NOT cause
variables to be re-set. This is one of "many" reasons why you want to use a
mde. I explain a few others in this article of mine: http://www.members.shaw.ca/AlbertKal...plit/index.htm
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada pl************* ****@msn.com http://www.members.shaw.ca/AlbertKallal
> However, that's not that concise and may not be the end of the story. Could there be any other bits that have escaped my attention? Does anyone want to try to complete the following sentence clearly and concisely: When an un-handled error occurs....
all variables get reset.
(that is 4 words, and is the end of the story).
You can see my other post, as I mentioned that using a mde will NOT reset
variables, and is on reason why they are far more reliable for your users.
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada pl************* ****@msn.com http://www.members.shaw.ca/AlbertKallal
Albert D. Kallal wrote: Actually, there is a simply catch all solution. Just distribute a mde to your users. All errors now, even when you don't trap them will NOT cause variables to be re-set. This is one of "many" reasons why you want to use a mde. I explain a few others in this article of mine:
It is not a reason why I want to use an mde. After an unhandled error I
want to require that the application be closed and, maybe, in some
situations, restarted, .. probably not. [A BSD woouldn't really upset
me]. A note to the developer would be a nice touch because the
unhandled arror shouldn't happen; it should be handled or fixed.
To those who say, "Oh, what an inconvenience!" , I say. "Learn your
trade!"; if you are just dabbling then dabble better.
> It is not a reason why I want to use an mde. After an unhandled want to require that the application be closed and, maybe, in some
Runtime does this to .mdb's. Unhandled errors cause the application to
close.
In an MDE, on unhandled errors the Runtime version discards the custom error
message, substitutes it's own error message, and continues.
(david)
"lylefair" <ly***********@ aim.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com... Albert D. Kallal wrote: Actually, there is a simply catch all solution. Just distribute a mde to your users. All errors now, even when you don't trap them will NOT cause variables to be re-set. This is one of "many" reasons why you want to use a mde. I explain a few others in this article of mine:
It is not a reason why I want to use an mde. After an unhandled error I want to require that the application be closed and, maybe, in some situations, restarted, .. probably not. [A BSD woouldn't really upset me]. A note to the developer would be a nice touch because the unhandled arror shouldn't happen; it should be handled or fixed.
To those who say, "Oh, what an inconvenience!" , I say. "Learn your trade!"; if you are just dabbling then dabble better.
On Sun, 13 Nov 2005 15:56:43 -0600, "David W. Fenton"
<dX********@bwa y.net.invalid> wrote: "Anthony England" <ae******@oops. co.uk> wrote in news:dl******* ***@nwrdmz01.dm z.ncs.ea.ibs-infra.bt.com:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level.
So if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a more detailed description of what happens when an un-handled error occurs - possibly with help file or website reference.
Example: Three buttons on a form, press them 1,2,3 (which causes an un-handled error) then back to 2. m_strCode is re-set.
Private m_strCode As String
Private Sub cmdOne_Click() m_strCode = "A1" End Sub
Private Sub cmdTwo_Click() MsgBox m_strCode End Sub
Private Sub cmdThree_Click( ) MsgBox CStr(1 / 0) End Sub Change the private module-level variable either to a function or a custom property:
Private Function strCode() As String Static strCodeStatic As String
If Len(strCodeStat ic) = 0 Then strCodeStatic = "A1" End If strCode = strCodeStatic End Function
OR:
Private Property Get strCode() As String Static strCodeStatic As String
If Len(strCodeStat ic) = 0 Then strCodeStatic = "A1" End If strCode = strCodeStatic End Property
I'm not sure that there's any advantage to one or the other.
The key here is that the value is set to a static variable internal to your function/property, and if the code has been reset, the static variable is re-assigned transparently.
I use the same approach. It works very nicely.
The advice I've given about avoiding global variables applies to module-level variables, too.
But, of course, private module-level variables are preferrable to global
because at least you can tell what procedures could touch the variables.
Also, we should add that module-level variables in class modules are very
appropriate (though not in massive numbers per module).
On Mon, 14 Nov 2005 00:53:19 GMT, "Albert D. Kallal" <ka****@msn.com > wrote: However, that's not that concise and may not be the end of the story. Could there be any other bits that have escaped my attention? Does anyone want to try to complete the following sentence clearly and concisely: When an un-handled error occurs....
all variables get reset.
(that is 4 words, and is the end of the story).
You can see my other post, as I mentioned that using a mde will NOT reset variables, and is on reason why they are far more reliable for your users.
But of course, the same cases that reset variables in an MDB exit an MDE
entirely. Basically, avoid all unhandled errors because they'll cause
problems for your users. At least, put error handlers in all event handler
procedures unless they do nothing but call other procedures with error
handlers, and do not resolve expressions ion parameter expressions.
"Steve Jorgensen" <no****@nospam. nospam> wrote in message
news:5a******** *************** *********@4ax.c om... On Mon, 14 Nov 2005 00:53:19 GMT, "Albert D. Kallal" <ka****@msn.com > wrote: But of course, the same cases that reset variables in an MDB exit an MDE entirely.
I believe you are describing what happens in the runtime, which has nothing to
do with the file being an MDE. Even in the runtime it is not entirely true that
an unhandlled error always causes the app to quit, but that is the most common
result.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Parintas Themis STE Kardias |
last post by:
Hi How can i use public variables. These variables i wand to use in
different places on a form (like a button) and are neccessery to write the
type of variable like:
Public VAR1, var2 as integer
or
Public VAR1, var2
Thanks
|
by: Al Smith |
last post by:
I need help in implementing proper error handling.
I am trying to upload a file based on the sample code below. The code works
well except if the file selected is too big.
I do know about the maxRequestLength parameter of the <httpRuntime> section
and that works as expected. What I want is to enforce a max file size but
haven't been able to trap the error thrown when the file is too large and
that's where I could use some help.
|
by: Mr Newbie |
last post by:
I'm testing error handling configurations and having some trouble. I created
a WebForm called. ErrDefault.aspx and I am trying to use the Page error
attribute to force the redirection to a custom page, but I only get and
unhandled exception page and it does not direct me to my specific page. I'm
probably doing something really stupid, but I cant see what .
Any Ideas ? - Thanx Mr N
--------- DETAILS BELOW -----------
|
by: James Radke |
last post by:
Hello,
I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module (note that this class module represents the business layer of code NOT the gui layer):
Public Function Test(ByVal Parm1 As Integer, ByVal Parm2 As Integer) As SqlDataReader
' Declare the SQL data layer class
Dim oSQL As New...
|
by: Stefan Johansson |
last post by:
Hi all
I'am moving from Visual Foxpro and have a question
regarding "best practice" error handling in vb .net.
In VFP I have always used a "central" error handling
object in order to have a easy and reusable way of
handling all errors in a program.
The VB 6 coding examples I have seen there has always
been error handling code in each program module.
| |
by: Gustaf |
last post by:
I'm confused about structured error handling. The following piece of
code is a simplification of a class library I'm working on. It works,
and it does what I want, but I'm still not convinced that I have been
doing it right. I think I overdo it. Please have a look:
--
using System;
using System.IO;
|
by: Anthony England |
last post by:
(sorry for the likely repost, but it is still not showing on my news server
and after that much typing, I don't want to lose it)
I am considering general error handling routines and have written a sample
function to look up an ID in a table. The function returns True if it can
find the ID and create a recordset based on that ID, otherwise it returns
false.
**I am not looking for comments on the usefulness of this function - it is
|
by: csgraham74 |
last post by:
Hi guys,
Basically i have been developing in dotnet for a couple of years but
ive had a few issues in regards to error handling.
For example - I have a class that i call passing in a stored procedure
and connection string as a path. My method returns a dataset. In my SP
i have an output parameter which tells me whether the SP select is
successful or not. If i get a error code passed back then i throw an
exception this then returns...
|
by: Lysander |
last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access Security, but I'll start with something short and simple
This code was written in Access 2003 but should be valid in Access 2000
By default, when you start a new module, either in a form or report, or a global module, Access does not declare Option...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |