Variables that I would like to make available to all forms and modules in my
program, where should I declare them? At the momment I just created a
module and have them all declared public there. What is the normal way to
do this?
Thanks,
Thomas
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access 27 2711
well i believe you do it just right , i also use a module for that , however
with one slight twist i use Friend instead of public in VB.Net modules
regards
M. Posseth [MCP]
<th*****@msala. net> wrote in message
news:43******** **************@ news.newsdemon. com... Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. What is the normal way to do this?
Thanks,
Thomas
-- Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ------->>>>>>http://www.NewsDemon.c om<<<<<<------ Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Thanks for the quick answer. I have been using VB2005 for about a month
now. I have never used Friend, but I will look it up and read about it.
Thomas
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
You declare them in a standard Module and make that Module the project's
startup item.
Friend level scope makes the item accessible anywhere IN the assembly.
Public scope makes the item accessible anywhere INSIDE or from OUTSIDE the
assembly.
<th*****@msala. net> wrote in message
news:43******** **************@ news.newsdemon. com... Thanks for the quick answer. I have been using VB2005 for about a month now. I have never used Friend, but I will look it up and read about it.
Thomas
-- Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ------->>>>>>http://www.NewsDemon.c om<<<<<<------ Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
> You declare them in a standard Module and make that Module the project's
startup item.
Scott M.,
Please correct me if I am wrong, but I am not sure if you *have* to set
the module as the start up object. That information might be misleading
to the OP. In my opinion, even if you do not set a module as a start up
object, and it is not an object module, meaning it is a standard
module, then the variable declared as public in that module will be
accessible globally throughout.
The scope of accessibility, of course, as you mentioned, will be global
if it is public and assembly scope, if it is friend.
Regards,
Sathyaish
You are correct that the standard Module need not be set as the Startup
Object in the project. I still recommend that it be set that way, as it is
more self-documenting in terms of programmatic flow.
"Sathyaish" <sa*******@gmai l.com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com... You declare them in a standard Module and make that Module the project's startup item.
Scott M.,
Please correct me if I am wrong, but I am not sure if you *have* to set the module as the start up object. That information might be misleading to the OP. In my opinion, even if you do not set a module as a start up object, and it is not an object module, meaning it is a standard module, then the variable declared as public in that module will be accessible globally throughout.
The scope of accessibility, of course, as you mentioned, will be global if it is public and assembly scope, if it is friend. Regards, Sathyaish
This might have been de-rigeur in the days of VB6 but VB.NET is an object
oriented language and there is no good excuse for a public variable anywhere
in such a system. They cause endless problems and should be avoided like the
plague.
Variables should always be private and accessed through correctly structured
get/set accessor properties.
In certain, very limited cases, you can use the shared keyword to provide
methods and properties that are globally available. These should however be
completely self-contained and not rely on any stored data such as a static
method referring to a static property and other such bad habits. The Math
class is the perfect example of where the Shared keyword is properly used.
If you want to develop good OOP techniques throw out just about everything
you learned from VB6.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
<th*****@msala. net> wrote in message
news:43******** **************@ news.newsdemon. com... Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. What is the normal way to do this?
Thanks,
Thomas
-- Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ------->>>>>>http://www.NewsDemon.c om<<<<<<------ Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
"Scott M." <s-***@nospam.nosp am> schrieb: You are correct that the standard Module need not be set as the Startup Object in the project. I still recommend that it be set that way, as it is more self-documenting in terms of programmatic flow.
In this case I prefer selecting 'Sub Main' as startup object. However, the
decision is up tp personal preference...
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
I have a form (Form2) which has a lot of overhead when it first loads so I
have a module containing sub main from which I start my application. In this
module, I declare a global variable for Form2 as below since it's shown as a
dialog in several places in my "mainform" as well as from otherr forms that I
show as dialogs from "mainform"
public myForm2 as Form2
sub main
'Show Splash screen
myForm2 = new Form2
'Close Splash screen
mainform.show
Application.Run ()
end sub
I find using the global variable myForm2 a lot easier and faster than trying
to declare the myForm2 in "mainform" then passing it as a property to other
forms that use myForm2 that are called as dialogs from "mainform"
How would you do it and yet retain the speed of only having to load Form2
once while a splash screen is showing.
--
Dennis in Houston
"Bob Powell [MVP]" wrote: This might have been de-rigeur in the days of VB6 but VB.NET is an object oriented language and there is no good excuse for a public variable anywhere in such a system. They cause endless problems and should be avoided like the plague.
Variables should always be private and accessed through correctly structured get/set accessor properties.
In certain, very limited cases, you can use the shared keyword to provide methods and properties that are globally available. These should however be completely self-contained and not rely on any stored data such as a static method referring to a static property and other such bad habits. The Math class is the perfect example of where the Shared keyword is properly used.
If you want to develop good OOP techniques throw out just about everything you learned from VB6.
-- Bob Powell [MVP] Visual C#, System.Drawing
Ramuseco Limited .NET consulting http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET. Subscribe to the RSS feeds provided and never miss a new article.
<th*****@msala. net> wrote in message news:43******** **************@ news.newsdemon. com... Variables that I would like to make available to all forms and modules in my program, where should I declare them? At the momment I just created a module and have them all declared public there. What is the normal way to do this?
Thanks,
Thomas
-- Posted via NewsDemon.com - Premium Uncensored Newsgroup Service ------->>>>>>http://www.NewsDemon.c om<<<<<<------ Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
This is where "Friend" level scope becomes useful. Public means that the
variable is available from anywhere within the assembly
as well as by external assmeblies that reference the first one.
Friend level scope means that the variable can be called by any code within
the assembly only.
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:8E******** *************** ***********@mic rosoft.com... I have a form (Form2) which has a lot of overhead when it first loads so I have a module containing sub main from which I start my application. In this module, I declare a global variable for Form2 as below since it's shown as a dialog in several places in my "mainform" as well as from otherr forms that I show as dialogs from "mainform"
public myForm2 as Form2
sub main 'Show Splash screen myForm2 = new Form2 'Close Splash screen mainform.show Application.Run () end sub
I find using the global variable myForm2 a lot easier and faster than trying to declare the myForm2 in "mainform" then passing it as a property to other forms that use myForm2 that are called as dialogs from "mainform"
How would you do it and yet retain the speed of only having to load Form2 once while a splash screen is showing. -- Dennis in Houston
"Bob Powell [MVP]" wrote:
This might have been de-rigeur in the days of VB6 but VB.NET is an object oriented language and there is no good excuse for a public variable anywhere in such a system. They cause endless problems and should be avoided like the plague.
Variables should always be private and accessed through correctly structured get/set accessor properties.
In certain, very limited cases, you can use the shared keyword to provide methods and properties that are globally available. These should however be completely self-contained and not rely on any stored data such as a static method referring to a static property and other such bad habits. The Math class is the perfect example of where the Shared keyword is properly used.
If you want to develop good OOP techniques throw out just about everything you learned from VB6.
-- Bob Powell [MVP] Visual C#, System.Drawing
Ramuseco Limited .NET consulting http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET. Subscribe to the RSS feeds provided and never miss a new article.
<th*****@msala. net> wrote in message news:43******** **************@ news.newsdemon. com... > > Variables that I would like to make available to all forms and modules > in > my > program, where should I declare them? At the momment I just created a > module and have them all declared public there. What is the normal way > to > do this? > > Thanks, > > Thomas > > -- > Posted via NewsDemon.com - Premium Uncensored Newsgroup Service > ------->>>>>>http://www.NewsDemon.c om<<<<<<------ > Unlimited Access, Anonymous Accounts, Uncensored Broadband Access This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jose Meireles |
last post by:
Hi everyone,
I'm trying to use public variables in a web form to hld specific values.
What happens is that the public variables (declared as public x as y in the
beginning of the class), doesn't seem to hold the value from function call
to function call.
Does anyone can help me abou this?
best regards
|
by: darrel |
last post by:
I'm still not quite sure how best to handle the passing of data between
controls.
This is a method I'm using at the moment:
I have an XML file that contains a variety of page-centric variables. I have
one control that loads the XML file, reads through it, and grabs the
variables it needs. It then sets these to PUBLIC variables.
Then, other usercontrols simply request that variable.
|
by: Mrs. Conni Drejer |
last post by:
Please help anyone: I have made a DLL (for DBCommunication) in which I have
defined some public static variables/fields in a public class. This because I
want these variables to be shared in all methods in the total application.
Both web- and windowsapplications and other DLL's are using this DLL. When
one of the Web-application uses the DLL, my variables are shared across
sessions, but I do not want this to happen - I want the variables to...
|
by: Webster |
last post by:
Hello,
Just wondering what's better programming style; to use public variables in a
class or to use private/protected variables and then expose them via
properties?
For example:
--------------------------------
Public Class public_person
|
by: Nick Dreyer |
last post by:
Is it possible to see public class variables of a COM addin in Excel 97 VBA?
I have successfully created the (Visual Basic 2003 .NET) COM
and referenced it in an Excel 97 VBA project. The VBA object browser sees -
and the project otherwise successfully interacts with - all the COM addin
methods and properties, but none of the public variables - target, init and
size in the code below - can be accessed. When I reference the exact same...
| |
by: Steve Mauldin |
last post by:
I have a public variable that is declared in a public module. This Variable
is stored into a Session variable and used to pass data from page to page.
I am seeing on my local development box that once the variable is created
and loaded with data and stored into the session variable that on the next
aspx page, before the first line of the page load is executed, the public
variables data persists. I have not done an assignment from the...
|
by: jopperdepopper |
last post by:
Hi,
finally giving php 5 a go, and going over the new approach to classes.
Can someone clarify the public, private and protected to me?
I quote the php manual: "The visibility of a property or method can be
defined by prefixing the declaration with the keywords: public,
protected or private. Public declared items can be accessed
everywhere."
|
by: Web Search Store |
last post by:
Hello,
I made a web page using visual studio.
I also made a public class in the app_code folder called 'allvars'
In the main web page durning the page startup, I can refer to public shared
variables by simply saying:
x=allvars.variable1
|
by: PhilippeM |
last post by:
Hi everyone!
I have defined 3 public variables:
Public OldCompany As Variant
Public OldLast As Variant
Public OldFirst As Variant
A procedure defines those variables:
OldCompany = !Company
OldLast = !
|
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,...
|
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...
| |
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |