473,785 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Module/ global variable problem

48 New Member
Hello again Humble helpfulls. Im having difficult with a module i have created. As its my first it was never going to be straightforward lol. But I was looking at one of the other treads and found it quite helpful about global variables but i eventually ran into difficulty..
the following code is for the click event that calls the Clicker Module
Expand|Select|Wrap|Line Numbers
  1. Private Sub Image30_Click()
  2. Dim counterx As Module
  3. Set counterx = Clicker
  4. counterx.IncrementCounter
  5.  
  6. If (counterx.GetCount > 3) Then
  7. DoCmd.OpenForm ("pcspecs2")
  8. counterx.ResetCounter
  9. Else
  10. Exit Sub
  11. End If
  12.  
Tye following is the code for my Clicker Module
Expand|Select|Wrap|Line Numbers
  1. Public count As Integer
  2.  
  3. Option Compare Database
  4.  
  5.  
  6. Public Function GetCount() As Integer
  7.     GetCount = count
  8. End Function
  9.  
  10. Public Function IncrementCounter()
  11.   count = count + 1
  12. End Function
  13.  
  14. Public Function ResetCounter()
  15. count = 0
  16. End Function
  17.  
The idea is that when the user click on an icon 3 times they will be brought to a new form. Any pointers on Module declareation and use would be apprieciated. Also i tried To initialise the count variable but it would not work. Can you not initialise a global variable or have i declared that wrong too lol.

Regards
Panteraboy
May 6 '08 #1
2 2024
ADezii
8,834 Recognized Expert Expert
Hello again Humble helpfulls. Im having difficult with a module i have created. As its my first it was never going to be straightforward lol. But I was looking at one of the other treads and found it quite helpful about global variables but i eventually ran into difficulty..
the following code is for the click event that calls the Clicker Module
Expand|Select|Wrap|Line Numbers
  1. Private Sub Image30_Click()
  2. Dim counterx As Module
  3. Set counterx = Clicker
  4. counterx.IncrementCounter
  5.  
  6. If (counterx.GetCount > 3) Then
  7. DoCmd.OpenForm ("pcspecs2")
  8. counterx.ResetCounter
  9. Else
  10. Exit Sub
  11. End If
  12.  
Tye following is the code for my Clicker Module
Expand|Select|Wrap|Line Numbers
  1. Public count As Integer
  2.  
  3. Option Compare Database
  4.  
  5.  
  6. Public Function GetCount() As Integer
  7.     GetCount = count
  8. End Function
  9.  
  10. Public Function IncrementCounter()
  11.   count = count + 1
  12. End Function
  13.  
  14. Public Function ResetCounter()
  15. count = 0
  16. End Function
  17.  
The idea is that when the user click on an icon 3 times they will be brought to a new form. Any pointers on Module declareation and use would be apprieciated. Also i tried To initialise the count variable but it would not work. Can you not initialise a global variable or have i declared that wrong too lol.

Regards
Panteraboy
Hello Panteraboy, I think you may want to take a different approach to this problem:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Image30_Click()
  2. 'Declaring a Variable as 'Static' enables it to retain its
  3. 'value between successive calls to this Click() Event
  4. Static intClickCount As Integer
  5.  
  6. intClickCount = intClickCount + 1
  7.  
  8. If intClickCount = 3 Then       'Image clicked 3 times
  9.   intClickCount = 0             'Reset Variable
  10.   'it's the 3rd click, so Open the Form
  11.   DoCmd.OpenForm "<Your Form Name>", YadaYadaYada...
  12. Else
  13.   'don't need this, but just an illustration to indicate
  14.   'that you take no action
  15. End If
  16. End Sub
May 6 '08 #2
panteraboy
48 New Member
Thanks a million. I had code similar to that but my variable wasnt static. Helpfull as always
Regards
Pantera boy
May 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
1888
by: Jacek Generowicz | last post by:
I have a module whose behaviour needs to be configurable. The module needs to decide, the first time it is imported, beteween alternative interfaces it presents. Currently, I set some environment variables which select the desired behaviour, and the module inspects those variables to determine the mode in which it should set itself up. I would prefer a pure Python solution, rather than one which depends on external state. Can you...
59
3947
by: seberino | last post by:
I've heard 2 people complain that word 'global' is confusing. Perhaps 'modulescope' or 'module' would be better? Am I the first peope to have thought of this and suggested it? Is this a candidate for Python 3000 yet? Chris
8
1947
by: Floris van Haaster | last post by:
Hi All! I have a question, i have a web application and I store some member information in a variable i declared in a module like: Public some_info_variable as string in module1.vb But when another user comes to my website he is getting the same values from the variable!!!
3
8914
by: hollowspook | last post by:
def aa(): global b b=b+1 print b b=1 aa() The above code runs well in python shell.
6
1723
by: ai | last post by:
It assumes that there is a module A which have two global variables X and Y. If I run "import A" in the IDLE shell, then I can use A.X and A.Y correctly. But if I want to change the module A and then delete the variable Y, I find I can use A.Y just the same as before! In fact, I have tried all the following methods but can't remove the A.Y: execute "import A" again "reload(A)" "del A; import A" Yes, if you use "del A.Y", it works. But...
4
2963
by: carl.dhalluin | last post by:
Hello I am completely puzzled why the following exec code does not work: mycode = "import math\ndef f(y):\n print math.floor(y)\nf(3.14)" def execute(): exec mycode execute()
0
816
by: thirunavukarasukm | last post by:
Hai.. Is thers possible to use module class in web application.. in web application i have one module class.. the module class one variable declared to assing particular value then i am go to mywebpage to print that modulevariable
0
2165
by: Fredrik Lundh | last post by:
Jeff Dyke wrote: so how did that processing use the "mymodulename" name? the calling method has nothing to do with what's considered to be a local variable in the method being called, so that only means that the name is indeed available in the global scope.
6
2272
by: dudeja.rajat | last post by:
Hi, I found on the net that there is something called module initialization. Unfortunately, there is not much information for this. However, small the information I found module initialization can be of use to me in my project. I'm currently messing with a problem where I'm keeping my global variables ( or symbols) in a module and the other mdoules in the project acess these global variables.
0
9647
marktang
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...
0
9485
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,...
0
10161
jinu1996
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...
1
10098
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,...
1
7506
isladogs
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...
0
6743
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();...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
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
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.