Sign Up |  Live StatsLive Stats    Articles 35,345| Comments 159,790| Members 17,820, Newest waheguruhelpme| Online 226
Home Contact
 (Forgotten?): 
    Sikhism

   
                                                                     Your Banner Here!    

Sikh Philosophy Network » Sikh Philosophy Network » Current Affairs » Information Technology » Make instant of a Class persistent for whole session.

Make instant of a Class persistent for whole session.

Our Donation Goal : Why Donate? : Donate Today! : Donate Anonymously (ਗੁਪਤ) : Our Family of Supporters
Goal this month: 400 USD, Received: 35 USD (9%)
Please Donate...
Related Topics...
Thread Thread Starter Forum Replies Last Post
India To make class 10 boards Exam optional kds1980 World 0 01-Sep-2009 01:09 AM
How can i verify my e-mail address in Instant Messaging? Lee Information Technology 1 19-Nov-2005 22:00 PM
Communicator Instant Message Linda Information Technology 1 18-Nov-2005 13:59 PM
Study Confirms Effectiveness of Drug for Persistent Asthma SPN Reporter Interfaith Dialogues 0 23-Mar-2005 03:30 AM
Instant messenger could control hacked computers Arvind Interfaith Dialogues 0 14-Oct-2004 02:28 AM


Tags
class, instant, make, persistent, session, whole
Reply Post New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!
  #1 (permalink)  
Old 28-Jul-2006, 08:40 AM
sime's Avatar sime
Guest
 
Posts: n/a
   
   
Make instant of a Class persistent for whole session.

  Donate Today!   Email to Friend  Tell a Friend   Show Printable Version  Print   Contact sikhphilosophy.net Administraion for any Suggestions, Ideas, Feedback.  Feedback  

Register to Remove Advertisements
Hello

When my database opens, I use Autoexec to run a function. In that
function I want to instantiate a class and have that instance remain
accessible for the whole session.

Specifically I am using the class to make variables efficiently
available to any other code.

I can do this with a form that hides itself - is that the only way to
do this? It seems a bit silly, but hey if that's the way I should do it
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/information-technology/13794-make-instant-class-persistent-whole-session.html
I won't complain.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794

Thanks
Simon




 
Do share your immediate thoughts or reactions on this issue? We value your views! Login Now! or Sign Up Today! to share your views with us.. Gurfateh!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 28-Jul-2006, 08:40 AM
Tom Wickerath's Avatar Tom Wickerath
Guest
 
Posts: n/a
   
   
RE: Make instant of a Class persistent for whole session.

Hi Simon,

Why can't you just declare the variables that you wish to persist as
globals, and set their value in the function that you run from your autoexec
macro. I really don't see the need to instantiate a class to accomplish this
goal. Something like this for determining the users NTUserID, and storing it
in the global variable named gstrUserName. Then just call the fOSUserName
function from your Autoexec macro.


Module name: basUtilities
Within this module:

' Get Login name
' http://www.mvps.org/access/api/api0008.htm

Option Compare Database
Option Explicit

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public gstrUserName As String

Function fOSUserName() As String
On Error GoTo ProcError

Dim lngLen As Long, lngX As Long
Dim strUserName As String

strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If

gstrUserName = fOSUserName

ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure fOSUserName..."
gstrUserName = "Unknown"
Resume ExitProc
End Function



Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
__________________________________________


"sime" wrote:

> Hello
>
> When my database opens, I use Autoexec to run a function. In that
> function I want to instantiate a class and have that instance remain
> accessible for the whole session.
>
> Specifically I am using the class to make variables efficiently
> available to any other code.
>
> I can do this with a form that hides itself - is that the only way to
> do this? It seems a bit silly, but hey if that's the way I should do it
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
> I won't complain.
>
> Thanks
> Simon
>
>

Reply With Quote
  #3 (permalink)  
Old 28-Jul-2006, 08:40 AM
sime's Avatar sime
Guest
 
Posts: n/a
   
   
Re: Make instant of a Class persistent for whole session.

Yes, that does the trick. And it works with Objects.

I had tried "Global" inside the class module, and I had tried your
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
suggestion with with things like "Static" and "Global Static". So
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
close!

Thanks heaps
Simon


Tom Wickerath wrote:
> Hi Simon,
>
> Why can't you just declare the variables that you wish to persist as
> globals, and set their value in the function that you run from your autoexec
> macro.


Reply With Quote
  #4 (permalink)  
Old 28-Jul-2006, 08:40 AM
Tom Wickerath's Avatar Tom Wickerath
Guest
 
Posts: n/a
   
   
Re: Make instant of a Class persistent for whole session.

Hi Simon,

You're welcome.

The only other thing you might do, just to help ensure that your global
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
variable will always have a value, is to use the Len function to ensure this
just prior to an attempt to reference it. Later versions of Access have been
much better than earlier versions about not losing global variables, however,
it is possible to lose the value if you are working in the Visual Basic
Environment, or it may not have been set in the first place if you opened
your database with the Shift key depressed in order to bypass the Autoexec
file. Here is an example:

If Len(gstrUserName) = 0 Then
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
fOSUserName ' Reinitialize value
End If

Select Case gstrUserName
Case blahblahblah
Do this
Case Else
Do that
End Select

This way, if the test for the length of your global variable is zero, a call
is made to re-initialize it just prior to attempting to do something with it,
such as Select Case.


Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/ex...tributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

"sime" wrote:

> Yes, that does the trick. And it works with Objects.
>
> I had tried "Global" inside the class module, and I had tried your
> suggestion with with things like "Static" and "Global Static". So
> close!
>
> Thanks heaps
> Simon

Reply With Quote
  #5 (permalink)  
Old 28-Jul-2006, 08:40 AM
sime's Avatar sime
Guest
 
Posts: n/a
   
   
Re: Make instant of a Class persistent for whole session.

Hehe, I came across this issue only an hour later. I was wondering if
there were any circumstances where the Global would lose it's value and
a bit of searching revealed that it can happen quite easily unless you
are careful with error handling (which I'm not) or creating an MDE
(which I'm not).

I have decided to take the "easy" option and have a hidden form. And
while I'm there I've turned it into a variable viewer and made it
visible during development.


Tom Wickerath wrote:
> Hi Simon,
>
> You're welcome.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
>
> The only other thing you might do, just to help ensure that your global
> variable will always have a value, is to use the Len function to ensure this
> just prior to an attempt to reference it. Later versions of Access have been
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
> much better than earlier versions about not losing global variables, however,
> it is possible to lose the value if you are working in the Visual Basic
> Environment, or it may not have been set in the first place if you opened
> your database with the Shift key depressed in order to bypass the Autoexec
> file. Here is an example:
>


Reply With Quote
  #6 (permalink)  
Old 28-Jul-2006, 08:40 AM
Smartin's Avatar Smartin
Guest
 
Posts: n/a
   
   
Re: Make instant of a Class persistent for whole session.

sime wrote:
> Hello
>
> When my database opens, I use Autoexec to run a function. In that
> function I want to instantiate a class and have that instance remain
> accessible for the whole session.
>
> Specifically I am using the class to make variables efficiently
> available to any other code.
>
> I can do this with a form that hides itself - is that the only way to
> do this? It seems a bit silly, but hey if that's the way I should do it
> I won't complain.
>
> Thanks
> Simon
>


I might be missing something, but what about instantiating the class at
the top of the module in which the function is called? This assumes the
function is in a standard module.

Module MyMod
============
Option Compare Database
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
Option Explicit

Set TheClass = New MyClass
------------------------------
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
Function AutoexecFunction()
blah blah blah
End Function

Don't forget to Set TheClass = Nothing before you close everything up.

--
Smartin
Reply With Quote
  #7 (permalink)  
Old 28-Jul-2006, 08:40 AM
Dirk Goldgar's Avatar Dirk Goldgar
Guest
 
Posts: n/a
   
   
Re: Make instant of a Class persistent for whole session.

"Smartin" wrote in message
news:K7KdnarfULdc7FjZnZ2dnUVZ_o2dnZ2d@giganews.com
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
>
> I might be missing something, but what about instantiating the class
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
> at the top of the module in which the function is called? This
> assumes the function is in a standard module.
>
> Module MyMod
> ============
> Option Compare Database
> Option Explicit
>
> Set TheClass = New MyClass
> ------------------------------
> Function AutoexecFunction()
> blah blah blah
> End Function
>
> Don't forget to Set TheClass = Nothing before you close everything up.


Won't work. Executable statements must be enclosed in procedures; they
can't just sit at the top of a module. And if they could, what event
would cause them to be executed?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Reply With Quote
  #8 (permalink)  
Old 28-Jul-2006, 08:40 AM
Smartin's Avatar Smartin
Guest
 
Posts: n/a
   
   
Re: Make instant of a Class persistent for whole session.

Dirk Goldgar wrote:
> "Smartin" wrote in message
> news:K7KdnarfULdc7FjZnZ2dnUVZ_o2dnZ2d@giganews.com
>> I might be missing something, but what about instantiating the class
>> at the top of the module in which the function is called? This
>> assumes the function is in a standard module.
>>
>> Module MyMod
>> ============
>> Option Compare Database
>> Option Explicit
>>
>> Set TheClass = New MyClass
>> ------------------------------
>> Function AutoexecFunction()
>> blah blah blah
>> End Function
>>
>> Don't forget to Set TheClass = Nothing before you close everything up.

>
> Won't work. Executable statements must be enclosed in procedures; they
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
> can't just sit at the top of a module. And if they could, what event
> would cause them to be executed?
>


I thought I was doing something similar at work, but I will check the
code tomorrow to be sure and clarify or withdraw my proposition. Thanks
for the heads-up.

--
Smartin
Reply With Quote
  #9 (permalink)  
Old 28-Jul-2006, 08:41 AM
Smartin's Avatar Smartin
Guest
 
Posts: n/a
   
   
Re: Make instant of a Class persistent for whole session.

  Donate Today!  
Smartin wrote:
> Dirk Goldgar wrote:
>> "Smartin" wrote in message
>> news:K7KdnarfULdc7FjZnZ2dnUVZ_o2dnZ2d@giganews.com
>>> I might be missing something, but what about instantiating the class
>>> at the top of the module in which the function is called? This
>>> assumes the function is in a standard module.
>>>
>>> Module MyMod
>>> ============
>>> Option Compare Database
>>> Option Explicit
>>>
>>> Set TheClass = New MyClass
>>> ------------------------------
>>> Function AutoexecFunction()
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
>>> blah blah blah
>>> End Function
>>>
>>> Don't forget to Set TheClass = Nothing before you close everything up.

>>
>> Won't work. Executable statements must be enclosed in procedures; they
>> can't just sit at the top of a module. And if they could, what event
>> would cause them to be executed?
>>

>
> I thought I was doing something similar at work, but I will check the
> code tomorrow to be sure and clarify or withdraw my proposition. Thanks
> for the heads-up.
>

Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794

My error, the declaration I am using is actually

Option Compare Database
Option Explicit

Public TheClass As New MyClass
--------------------------------------

Works great. The class is accessible to other modules and forms.

--
Smartin
Reply With Quote
   Click Here to Donate Now!

Support Us!
Become a Promoter!
Gurfateh ji, you can become a SPN Promoter by Donating as little as $10 each month. With limited resources & high operational costs, your donations make it possible for us to deliver a quality website and spread the teachings of the Sri Guru Granth Sahib Ji, to serve & uplift humanity. Every contribution counts. Donate Generously. Gurfateh!
ReplyPost New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!

Bookmarks


(View-All Members who have read this thread : 0
There are no names to display.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Tools Search
Search:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

» Gurbani Jukebox
Listen to Gurbani while surfing SPN!
» Active Discussions
sikhism Who is "Mohan"?
Today 08:46 AM
22 Replies, 335 Views
sikhism How important is Matha...
Today 08:12 AM
59 Replies, 1,038 Views
sikhism need urgent advice.......
Today 06:46 AM
6 Replies, 81 Views
sikhism ਨਾਮਾ
Today 06:37 AM
2 Replies, 53 Views
sikhism Sikh Diamonds Video...
Today 04:23 AM
6 Replies, 116 Views
sikhism Are Creator and Creation...
Today 01:30 AM
44 Replies, 2,837 Views
sikhism Herman Hesse,...
Today 00:54 AM
13 Replies, 229 Views
sikhism On a Scale of Most...
Yesterday 21:42 PM
30 Replies, 1,277 Views
sikhism I became victim by...
Yesterday 19:50 PM
0 Replies, 44 Views
sikhism Sikh Books downloads
Yesterday 15:39 PM
2 Replies, 66 Views
sikhism Salok Sheikh Farid ji...
Yesterday 09:35 AM
0 Replies, 47 Views
sikhism In Punjab, three farmers...
Yesterday 05:36 AM
0 Replies, 49 Views
sikhism Supernatural Sikhs, what...
Yesterday 03:45 AM
19 Replies, 414 Views
sikhism Sukhmani Sahib Astpadi...
26-May-2012 22:57 PM
0 Replies, 51 Views
Do You Think You Are...
26-May-2012 09:59 AM
94 Replies, 8,258 Views
» Books You Should Read...
Powered by vBadvanced CMPS v3.2.2

All times are GMT +6.5. The time now is 09:43 AM.
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.2 Copyright © 2004-12, All Rights Reserved. Sikh Philosophy Network


Page generated in 0.52017 seconds with 30 queries