473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Module/ global variable problem

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 2007
ADezii
8,834 Expert 8TB
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
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
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...
59
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...
8
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...
3
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
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...
4
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
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...
0
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...
6
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.