Is there any place or method to hold or pass some global variables, ie user
name, user level..., that can be shared within the whole application which
has a lot of dll and user defined components?
I am work on Visual Basic 2002.
Thanks a lot! 4 1632
Hello BB206,
Is there any place or method to hold or pass some global variables, ie user
name, user level..., that can be shared within the whole application which
has a lot of dll and user defined components?
When using global variables, please keep in mind that it can be changed
anywhere in your code. If it is that you mainly need to read it's value
then it would be better to make a class and a property, e.g.
Public Class clsGLOBAL
Private Shared vVariable1 As Integer = 10
Public Shared ReadOnly Property Variable1() As Integer
Get
Return vVariable1
End Get
End Property
End Class
This way, you can access your variable with clsGLOBAL.Variable1 and you
don't have to worry that by mistake you change the value of that
variable. Still, in the class clsGLOBAL you can change it as required.
Best regards,
Martin
Thank you Martin, But how to pass the class from one class to another class.
I had written some class dlls that has no way to pass the class between
them.
Thanks!
"Martin H." <hk***@gmx.net>
???????:46***********************@news.freenet.de. ..
Hello BB206,
>Is there any place or method to hold or pass some global variables, ie user name, user level..., that can be shared within the whole application which has a lot of dll and user defined components?
When using global variables, please keep in mind that it can be changed
anywhere in your code. If it is that you mainly need to read it's value
then it would be better to make a class and a property, e.g.
Public Class clsGLOBAL
Private Shared vVariable1 As Integer = 10
Public Shared ReadOnly Property Variable1() As Integer
Get
Return vVariable1
End Get
End Property
End Class
This way, you can access your variable with clsGLOBAL.Variable1 and you
don't have to worry that by mistake you change the value of that variable.
Still, in the class clsGLOBAL you can change it as required.
Best regards,
Martin
Hello BB206,
here's an example:
Public Class clsGLOBAL
Private Shared vVariable1 As Integer = 10
Public Shared ReadOnly Property Variable1() As Integer
Get
Return vVariable1
End Get
End Property
End Class
Public Class Test
Private Sub Foo()
MsgBox (clsGLOBAL.Variable1.ToString)
End Sub
End Class
As you can see, the sub "Foo" references clsGLOBAL.Variable1 without the
need of an instance. This is, because it is a shared property. The side
effect of shared properties is that they require a shared variable
behind (vVariable1 is also "Shared"). "Shared" variables can only be
used in "Shared" subs/functions.
If you don't want to use "Shared" variables, you have to create an
instance of that class.
Public Class clsGLOBAL2
Private vVariable1 As Integer = 10
Public ReadOnly Property Variable1() As Integer
Get
Return vVariable1
End Get
End Property
End Class
Public Class Test
Private Sub Foo()
dim ClsGlbl2 As New clsGLOBAL2
MsgBox (ClsGlbl2.Variable1.ToString)
End Sub
End Class
Best regards,
Martin
BB206 wrote:
Thank you Martin, But how to pass the class from one class to another class.
I had written some class dlls that has no way to pass the class between
them.
Thanks!
"Martin H." <hk***@gmx.net>
???????:46***********************@news.freenet.de. ..
>Hello BB206,
>>Is there any place or method to hold or pass some global variables, ie user name, user level..., that can be shared within the whole application which has a lot of dll and user defined components?
When using global variables, please keep in mind that it can be changed anywhere in your code. If it is that you mainly need to read it's value then it would be better to make a class and a property, e.g.
Public Class clsGLOBAL Private Shared vVariable1 As Integer = 10
Public Shared ReadOnly Property Variable1() As Integer Get Return vVariable1 End Get End Property End Class
This way, you can access your variable with clsGLOBAL.Variable1 and you don't have to worry that by mistake you change the value of that variable. Still, in the class clsGLOBAL you can change it as required.
Best regards,
Martin
I got it, Thanks a lot!
"Martin H." <hk***@gmx.net>
???????:46***********************@news.freenet.de. ..
Hello BB206,
here's an example:
Public Class clsGLOBAL
Private Shared vVariable1 As Integer = 10
Public Shared ReadOnly Property Variable1() As Integer
Get
Return vVariable1
End Get
End Property
End Class
Public Class Test
Private Sub Foo()
MsgBox (clsGLOBAL.Variable1.ToString)
End Sub
End Class
As you can see, the sub "Foo" references clsGLOBAL.Variable1 without the
need of an instance. This is, because it is a shared property. The side
effect of shared properties is that they require a shared variable behind
(vVariable1 is also "Shared"). "Shared" variables can only be used in
"Shared" subs/functions.
If you don't want to use "Shared" variables, you have to create an
instance of that class.
Public Class clsGLOBAL2
Private vVariable1 As Integer = 10
Public ReadOnly Property Variable1() As Integer
Get
Return vVariable1
End Get
End Property
End Class
Public Class Test
Private Sub Foo()
dim ClsGlbl2 As New clsGLOBAL2
MsgBox (ClsGlbl2.Variable1.ToString)
End Sub
End Class
Best regards,
Martin
BB206 wrote:
>Thank you Martin, But how to pass the class from one class to another class. I had written some class dlls that has no way to pass the class between them.
Thanks!
"Martin H." <hk***@gmx.net> ???????:46***********************@news.freenet.de ...
>>Hello BB206,
Is there any place or method to hold or pass some global variables, ie user name, user level..., that can be shared within the whole application which has a lot of dll and user defined components? When using global variables, please keep in mind that it can be changed anywhere in your code. If it is that you mainly need to read it's value then it would be better to make a class and a property, e.g.
Public Class clsGLOBAL Private Shared vVariable1 As Integer = 10
Public Shared ReadOnly Property Variable1() As Integer Get Return vVariable1 End Get End Property End Class
This way, you can access your variable with clsGLOBAL.Variable1 and you don't have to worry that by mistake you change the value of that variable. Still, in the class clsGLOBAL you can change it as required.
Best regards,
Martin
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David Hitillambeau |
last post by:
Hi guys,
As I am new to Python, i was wondering how to declare and use global
variables. Suppose i have the following structure in the same module (same
file):
def foo:
<instructions>...
|
by: Andrew V. Romero |
last post by:
I have been working on a function which makes it easier for me to pull
variables from the URL. So far I have:
<script language="JavaScript">
var variablesInUrl;
var vArray = new Array();
...
|
by: Dan Elliott |
last post by:
Hello,
Converting from a working C program to C++, I run into the following error:
I have a header: (header.h)
namespace shared{
...
struct X{
...
|
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
{...
|
by: lawrence |
last post by:
I'm learning Javascript. I downloaded a script for study. Please tell
me how the variable "loop" can have scope in the first function when
it is altered in the second function? It is not defined...
|
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...
|
by: Charles O'Flynn |
last post by:
As a complete newcomer (2-3 days) to PHP, although not to programming in
general, I have 'dived in' to start a small project to read and parse an XML
data stream. I have already worked out most of...
|
by: Ed Jensen |
last post by:
I'm having a vexing problem with global variables in Python. Please
consider the following Python code:
#! /usr/bin/env python
def tiny():
bar =
for tmp in foo:
bar.append(tmp)
foo = bar
|
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...
|
by: istillshine |
last post by:
When I control if I print messages, I usually use a global variable
"int silent". When I set "-silent" flag in my command line
parameters, I set silent = 1 in my main.c.
I have many functions...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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: 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...
|
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...
| |