473,387 Members | 1,532 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.

How to use global variables in VBA?

Hello, trying to implement a global variable iTable that I can increment/decrement and use its value anytime needed.

1. globalvariables module:
Expand|Select|Wrap|Line Numbers
  1. Global iTable As Integer
2. One of my subs that change its value:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtProduct1_Enter()
  2.     iTable = 3
  3. End Sub
3. Sub where I call it with a Select Case
Expand|Select|Wrap|Line Numbers
  1. Private Sub populateTxtOnEnter(ByVal copy As String, ByVal iTable As Integer)
  2.     Select Case iTable
  3.     Case 1
  4.         MsgBox "ERROR"
  5.         txtClient.Value = copy
  6.         textTicket.SetFocus
  7.     Case 2
  8.         textTicket.Value = copy
  9.         txtProduct1.SetFocus
  10.     Case 3
  11.         txtProduct1.Value = copy
  12.         'txtSize1.SetFocus
  13.     Case 4
  14.         txtSize1.Value = copy
  15.         txtQuantity1.SetFocus
  16.     End Select   
  17. End Sub

Now, altough I enter txtProduct1 TextBox, and my iTable is changed to 3, when the code reachs the Select Case, it always goes Case 1 and displays "ERROR" MsgBox that I created. I ask you why?

I tried a MsgBox on txtProduct1_Enter and it gave me iTable = 3.
Nov 19 '14 #1

✓ answered by Satsulima

Solved. No problems on global variables, other subs are calling one that puts iTable back on 1, hence the problem.

2 1041
How can its value change back to 1? Please help
Nov 19 '14 #2
Solved. No problems on global variables, other subs are calling one that puts iTable back on 1, hence the problem.
Nov 19 '14 #3

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

Similar topics

1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
10
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can...
5
by: Richard A. DeVenezia | last post by:
Dear Experts: Suppose I have global variables: x1, x2, x3 and I have a function that needs to assign a value to a new global variable x4 something like function foo () { count = 0;
2
by: Patient Guy | last post by:
I have a library of functions representing a filesystem interface (essentially a file selection interface, to be used in opening/reading/writing/closing files). Heavily scripted HTML document...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
7
by: zeecanvas | last post by:
Hi, First of all: Yes, I know global variables are bad, but I've a huge amount of legacy code, and I've to maintain it _as_is_. I'm maintaining a big program. I moved all (program-wide scope)...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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.