473,431 Members | 1,564 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,431 software developers and data experts.

Proper use of global variables for reports

Hello all,

I just got my first job in the IT field as a junior programmer. Right
now I am working on my first assignment. It's not the best assignment in the
world, but it's something I have thought about. My assignment is:

Change all logos on reports in some Access 2000 Database to some other
value.

Each Logo is really just a label with the same text but it is displayed
differently depending on the report. It's not that I don't know how to do
this but I was wondering if this is a good job for a global variable?

What I want to do is declare a global variable, and then any form that
has to display the logo refrences that variable. I think it would be ok, but
many of my teachers have told me not to ever use them. Do you think it's a
good idea to run by my boss or should I just shut up and do it the manual
way?

Thanks,
Brent


Dec 13 '05 #1
3 9032
Hi Brent,

When performing tasks of similar nature I like to declare a global
constant (eg: Global Const gstrTitle as String = "Some text Here" &
vbcrlf & "Second line here") especially when the value changes so
rarely. Declaring it as a constant will save you having to declare the
value at startup. Alternatively, you could store the string in a number
of locations ie: external file, custom properties, table etc. I would
be interested to learn why your teachers have told you not to declare
global variables. Anyway, if you need more information to help you with
this task let me know.

Anton

Dec 14 '05 #2
Per Brent Ritchie:
What I want to do is declare a global variable, and then any form that
has to display the logo refrences that variable. I think it would be ok, but
many of my teachers have told me not to ever use them. Do you think it's a
good idea to run by my boss or should I just shut up and do it the manual
way?


I'd wrap the global in a function and then call the function.

e.g.

-------------------------------------------------
Const gWhatEver = "xyz"
-------------------------------------------------
-------------------------------------------------
Public Function CommonReportHeader() As String

CommonReporHeader = gWhatEver

End Function
--------------------------------------------------
--------------------------------------------------
Report_Open()
Me.txtReportHeader = CommonReportHeader()
End Sub
--------------------------------------------------
At first this looks a little convoluted, but one advantage is that once you get
it all running, move on to other things, and get stronger with VB; you have the
option of going back and re-coding CommonReportHeader() so that, instead of
getting the value from a global constant, it gets it from a .INI file, some
parm table in the DB, or even a freestanding text file.

Another advantage is that if someday, for some reason, you want to pull that (or
some other) data into a query you can call the same function.
I kind of like the .INI file approach. Then, if/when you wind up with common
boilerplate in many reports across many applications, the text only resides in a
single place.

The downsides of a .INI file solution would be the extra documentation and
(depending on the environment) the prospect of people being able to make
uncontrolled/undocumented changes - whereas with the data residing in a global
in the app, somebody would have to make a new rev of the app in order to change
it.
Especially within the confines of MS Access, I wouldn't agree with "never" when
it comes to globals. What I would say is that I'd better have a *really* good
reason to use a global instead of passing arguments from routine-to-routine.

My take on this subject comes from "Code Complete" by Steve McConnell/Microsoft
Press. Personally, I'd recommend that book to anybody anywhere as soon as they
find out they will be writing code.
--
PeteCresswell
Dec 14 '05 #3
Put a logo in a table.

Change the recordsource on all reports to reference that table.

or, (not as good), create a subreport with the logo, and
use the sub-report instead of using the logo directly.

or, (not good, but better than what you have), use code in
the report setup to get and display the logo.

It is almost never a good idea to have multiple copies of a logo.
Yes, this is a good job for a 'global variable'. In this case,
a good job for a global table record 'variable', with a field
which contains the logo.

No not a good job for a global VBA variable. You need a
persistent variable (a file or a database record) in which
to store the data, and there is probably no good reason
to copy the data from the global persistent variable to
a global VBA memory variable.

But if you only have 5 reports, the time it would take to change
the logo's is less than the time you have already spent thinking
about this.

(david)

"Brent Ritchie" <br**********@personainternet.com> wrote in message
news:sO******************@news20.bellglobal.com...
Hello all,

I just got my first job in the IT field as a junior programmer. Right
now I am working on my first assignment. It's not the best assignment in
the world, but it's something I have thought about. My assignment is:

Change all logos on reports in some Access 2000 Database to some other
value.

Each Logo is really just a label with the same text but it is displayed
differently depending on the report. It's not that I don't know how to do
this but I was wondering if this is a good job for a global variable?

What I want to do is declare a global variable, and then any form that
has to display the logo refrences that variable. I think it would be ok,
but many of my teachers have told me not to ever use them. Do you think
it's a good idea to run by my boss or should I just shut up and do it the
manual way?

Thanks,
Brent

Dec 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
1
by: seberino | last post by:
Python lets me access module level variables from *anywhere*. All I have to do is add module name in front. e.g. mymodule.myvariable Is this considered a 'global'? Or, does a 'global...
3
by: Dalan | last post by:
I need some assistance or advise in composing code for a global function module or a related one for populating values in text boxes on reports and forms with a name, actually several different...
4
by: DerekM | last post by:
I have a database project that I created with several forms and reports. I would like to be able to declare a single title and be able to change the title on all the forms and reports by changing...
33
by: DFS | last post by:
An application I wrote has been deployed on Citrix, and the Citrix admin tells me all users run the same .mde file. There aren't a lot of concurrent users, but even 2 could be cause for concern. ...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
2
by: bob | last post by:
Let's say that a class only allows proper initialization through its constructor. Let's also say that you need a global variable of that class, but you can't initialize it at the beginning of the...
11
by: giddy | last post by:
hi , ok , i have a programming background but i'm new to C# . i'm also self taught so : i have a datagridview that should act differently depending on which user has signed in now is it...
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...
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
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...
1
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...
0
tracyyun
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...
0
agi2029
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.