Can you store "public" variables that may be accessed from anywhere and
still have a Form (not SubMain) as the designated startup object ?
For example.... let's say I want all the form's Text property equal to
"Program Name and Version"
In a public class I tried....
Public Class SomeVariables
Public strProgNameVer as String = "My Name"
End Class
On the load of Form1 I placed
Me.Text = strProgNameVer
Nothing appeared in the text property of the form AND the program did not
crash due to lack of a declaration of strProgNameVer.
I kind of expected one or the other... either see the text, or crash due to
errror...
Thanks ! 13 1268
"Rob" <ro***@yahoo.co mwrote in message
news:Iq******** *************** *******@comcast .com...
Can you store "public" variables that may be accessed from anywhere and
still have a Form (not SubMain) as the designated startup object ?
For example.... let's say I want all the form's Text property equal to
"Program Name and Version"
In a public class I tried....
Public Class SomeVariables
Public strProgNameVer as String = "My Name"
End Class
I don't think you can get away with it. The variable declaration has to be
in the scope of the class being used to be seen. Apparently, all you did up
above was make a local variable that can only be seen in the class above.
Public Class Form1 is a class.
>
On the load of Form1 I placed
Me.Text = strProgNameVer
Nothing appeared in the text property of the form AND the program did not
crash due to lack of a declaration of strProgNameVer.
Maybe, your project doesn't have Option Explicit set to (ON), which will
allow a none declared variable to be used, initialized to nullstring in this
case and the will not blow up because of it or show a compile error.
>
I kind of expected one or the other... either see the text, or crash due
to errror...
If you're not trying to do that below, then maybe you need to be using a
global Variableobj to hold and access global variables.
Public Class Form1
Public teststr As String = "Help"
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Me.Text = teststr
End Sub
End Class
So try this:
1) Create a Public Class Named Settings
2) in that class create a public shared member called name as string
Public Shared name As String = "Myname"
3) In your form you can now use the value Settings.name and get the string
'Myname' from it.
"Rob" <ro***@yahoo.co mwrote in message
news:Iq******** *************** *******@comcast .com...
Can you store "public" variables that may be accessed from anywhere and
still have a Form (not SubMain) as the designated startup object ?
For example.... let's say I want all the form's Text property equal to
"Program Name and Version"
In a public class I tried....
Public Class SomeVariables
Public strProgNameVer as String = "My Name"
End Class
On the load of Form1 I placed
Me.Text = strProgNameVer
Nothing appeared in the text property of the form AND the program did not
crash due to lack of a declaration of strProgNameVer.
I kind of expected one or the other... either see the text, or crash due
to errror...
Thanks !
Thanks Ray !!!
"Ray Cassick" <rc******@enter procity.comwrot e in message
news:OR******** ******@TK2MSFTN GP03.phx.gbl...
So try this:
1) Create a Public Class Named Settings
2) in that class create a public shared member called name as string
Public Shared name As String = "Myname"
3) In your form you can now use the value Settings.name and get the string
'Myname' from it.
"Rob" <ro***@yahoo.co mwrote in message
news:Iq******** *************** *******@comcast .com...
>Can you store "public" variables that may be accessed from anywhere and still have a Form (not SubMain) as the designated startup object ?
For example.... let's say I want all the form's Text property equal to "Program Name and Version"
In a public class I tried....
Public Class SomeVariables
Public strProgNameVer as String = "My Name"
End Class
On the load of Form1 I placed
Me.Text = strProgNameVer
Nothing appeared in the text property of the form AND the program did not crash due to lack of a declaration of strProgNameVer.
I kind of expected one or the other... either see the text, or crash due to errror...
Thanks !
"Ray Cassick" <rc******@enter procity.comwrot e in message
news:OR******** ******@TK2MSFTN GP03.phx.gbl...
So try this:
1) Create a Public Class Named Settings
2) in that class create a public shared member called name as string
Public Shared name As String = "Myname"
3) In your form you can now use the value Settings.name and get the string
'Myname' from it.
You certainly cannot get away with this in C#. I see you can do this in
VB.net. I guess my question would be why would you do this?
Why wouldn't you just have a Module.vb with a Public Const set or even
Public Name as String = "Hello"?
Hi,
I think I did try that, but maybe i did something else wrong... ...
>>Why wouldn't you just have a Module.vb with a Public Const set or even Public Name as String = "Hello"?
As to why not start with Sub Main() (which is my interpretation of what you
are saying)...
In VB.net - I could start out with Sub Main, however, then you lose other
startup options.... watch the check boxes when you do.
So, I was wanting to keep the Open Form as the first step, then access the
public varibles whenever I want them.
Thanks
"Mr. Arnold" <MR. Ar****@Arnold.c omwrote in message
news:uG******** ******@TK2MSFTN GP06.phx.gbl...
>
"Ray Cassick" <rc******@enter procity.comwrot e in message
news:OR******** ******@TK2MSFTN GP03.phx.gbl...
>So try this:
1) Create a Public Class Named Settings
2) in that class create a public shared member called name as string
Public Shared name As String = "Myname"
3) In your form you can now use the value Settings.name and get the string 'Myname' from it.
You certainly cannot get away with this in C#. I see you can do this in
VB.net. I guess my question would be why would you do this?
Why wouldn't you just have a Module.vb with a Public Const set or even
Public Name as String = "Hello"?
"Rob" <ro***@yahoo.co mwrote in message
news:4-*************** *************** @comcast.com...
Hi,
I think I did try that, but maybe i did something else wrong... ...
>>>Why wouldn't you just have a Module.vb with a Public Const set or even Public Name as String = "Hello"?
As to why not start with Sub Main() (which is my interpretation of what
you are saying)...
In VB.net - I could start out with Sub Main, however, then you lose other
startup options.... watch the check boxes when you do.
So, I was wanting to keep the Open Form as the first step, then access the
public varibles whenever I want them.
VB is a different animal. It's always been that way starting back to VB 3.0.
MS has kept some concepts in VB that don't lend itself towards good Oops
programming practices, like making a Public variable visible that can be
seen globally. One may be able to use this concept in doing Windows desktop
development, which should be on a limited basis, and it should never be used
in a Web solution.
"Mr. Arnold" <MR. Ar****@Arnold.c omwrote in message
news:u3******** ******@TK2MSFTN GP05.phx.gbl...
>
"Rob" <ro***@yahoo.co mwrote in message
news:4-*************** *************** @comcast.com...
>Hi,
I think I did try that, but maybe i did something else wrong... ...
>>>>Why wouldn't you just have a Module.vb with a Public Const set or even Public Name as String = "Hello"?
As to why not start with Sub Main() (which is my interpretation of what you are saying)... In VB.net - I could start out with Sub Main, however, then you lose other startup options.... watch the check boxes when you do.
So, I was wanting to keep the Open Form as the first step, then access the public varibles whenever I want them.
VB is a different animal. It's always been that way starting back to VB
3.0. MS has kept some concepts in VB that don't lend itself towards good
Oops programming practices, like making a Public variable visible that can
be seen globally. One may be able to use this concept in doing Windows
desktop development, which should be on a limited basis, and it should
never be used in a Web solution.
Two points...
1) I would have not really recommended this in a web solution. Web was not
mentioned.
2) The user has to be completely aware of the implication of using ANY
global variables.
When I went to college my professor told me that if one of my applications
was going to use a global variable I needed a note from my mom. I hate
talking to my mom so I never used them :)
Anyone can write crap in any language.
Just because VB lets you do things that maybe you should not do does not
make it a bad language. Hell if that was the case the inventor of C should
be shot in the head. But I am not going to get into a religious language
argument here.
He asked a question and I answered it.
Rob, He is right though. Any time you are considering using a global
variable the first thing you need to ask yourself is WHY? I have never seen
a case where it could not be solved another way that in the end gets you
better code that is simpler to maintain and preserves good OOP design.
>
Just because VB lets you do things that maybe you should not do does not
make it a bad language. Hell if that was the case the inventor of C should
be shot in the head. But I am not going to get into a religious language
argument here.
I never said VB was a bad language. I have used VB for many years, more
years that I would even care to remember. However, since VB.Net is
proprietary to MS and is not a standard, unlike C#.Net, then MS can take
liberties with VB.NET that will allow a developer to do things, because MS
doesn't have to answer to anyone.
Got it. Might have been on the offensive too quick there :)
Too many years of putting up with VB Bashers :)
"Mr. Arnold" <MR. Ar****@Arnold.c omwrote in message
news:uF******** ******@TK2MSFTN GP02.phx.gbl...
Just because VB lets you do things that maybe you should not do does not make it a bad language. Hell if that was the case the inventor of C should be shot in the head. But I am not going to get into a religious language argument here.
I never said VB was a bad language. I have used VB for many years, more
years that I would even care to remember. However, since VB.Net is
proprietary to MS and is not a standard, unlike C#.Net, then MS can take
liberties with VB.NET that will allow a developer to do things, because MS
doesn't have to answer to anyone.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: robert walker |
last post by:
hi all,
to my webapp named mrf, i have added load-on-startup tag
to mrf\WEB-INF\web.xml
so i added a snippet like so
<servlet>
<servlet-name>loadDbProperties</servlet-name>
<servlet-class>mrf.LoadDbPropertiesServlet</servlet-class>
|
by: wolftor |
last post by:
If I change the application title, it appears to change OK during the
current session; but if I exit Access 97 and then run the application again,
the change did not get saved. Any idea how to fix this and what's causing
it?
--
Regards,
Peter
|
by: Stuart Clark |
last post by:
Hi,
I am having quite a major problem with an access database. Basically,
under "Tools => Startup", there are options to disable the Menu's
(e.g. - file, tools etc), the toolbars, the main window, and in fact,
everything.
A vital database has had everything disabled, and so the menus and
windows no longer load when I open the database. This means I can't
get to the
|
by: cefrancke |
last post by:
I cant seem to find a straight answer on the following.
I want to programmatically hide all menus except a basic custom report
menu (during report preview) and right click pop-up A-Z sorting on
datasheets (for subforms).
I would like to do this on startup of the application.
To be clear:
|
by: cefrancke |
last post by:
I have set the Startup properties to the following...
All menus, toolbars, etc are turned off plus these are unchecked
Allow Full Menus
Allow Built-in Toolbars
Allow Default Shortcut Menus
Allow Toolbar/Menu Changes
Use Access Special Keys
| |
by: deko |
last post by:
I'm trying to set startup properties with code after I make an MDB into an
MDE.
I have this code in the startup form's Form_Open event:
If IsItMde Then
For Each var In Array("Perform Name AutoCorrect", _
"Track Name AutoCorrect Info", "StartUpShowDBWindow", _
"StartUpShowStatusBar", "AllowFullMenus", "AllowBuiltInToolbars", _
|
by: PC Datasheet |
last post by:
How can I programatically set the startup form when the database opens?
Thanks!
Steve
|
by: Chris Ashley |
last post by:
I have a class called App set as the startup object with the following code:
Friend Class App
Shared Sub Main()
Dim FrmMain As New MainForm
Application.Run(FrmMain)
End Sub
End Class
In another form I use the following code:
|
by: cj |
last post by:
I found a good tutorial for making a windows setup program so I'm doing
that. But when I add folders to the target machine list they don't seem
to have one for the all users startup folder. I assume this will be a
custom location and I added one called Startup. Now I'm looking at the
properties menu for it but I'm not sure how to set the properties to
specify the all users startup folder--if it exists, user startup if not.
|
by: Jeff Ciaccio |
last post by:
I'm new to vb.net and was wondering what the syntax is for application
events such as starting up or shutting down. For example, if you would just
like to get a user's name with an input box when they open the app or a
form.
Thanks
--
Jeff Ciaccio
Physics and AP Physics Teacher
|
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: 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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: 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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |