473,325 Members | 2,785 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,325 software developers and data experts.

global data in .net

i am a newbie to .net programming, i am having problem
with global data and form instanciation. My questions are
How do i maintain global data in windows forms
applications? How do i navigate from one form to another
form class? (example me.hide() and form2.show)
TIA
CSP
Nov 20 '05 #1
3 3643
In VB6, you were able to refer to any form by the form-name (like Form1,
frmMain, etc) and you were also able to create multiple instances of any
form like:
Dim frm as New Form2

In VB.NET you cannot code against the form-name (the class) anymore. You
always have to create an instance of any form before using it. The new
problem here is that you cannot get a hold on any of the application's forms
(instances) unless you have a public variable referencing that form for you
to use (global data as you said).
One way of doing that is adding a Module to your app and declaring variables
to hold references to the form instances that you'll need across your app:

Module YourModule
Public mainForm as frmMain
Public clockForm as frmClock

End Module

In your code, when you open the main form for the first time, you store the
reference in the appropriate variable:

mainForm = New frmMain()
mainForm.Show()

Then you can use the variable mainForm anywhere else in your app to
manipulate the main form.

That's the idea.

HTH
--
TJoker, MCSD.NET
MVP: Paint, Notepad, Solitaire

****************************************
"CsProviders" <CS*********@yahoo.com> wrote in message
news:01****************************@phx.gbl...
i am a newbie to .net programming, i am having problem
with global data and form instanciation. My questions are
How do i maintain global data in windows forms
applications? How do i navigate from one form to another
form class? (example me.hide() and form2.show)
TIA
CSP

Nov 20 '05 #2
"CsProviders" <CS*********@yahoo.com> schrieb
i am a newbie to .net programming, i am having problem
with global data and form instanciation. My questions are
How do i maintain global data in windows forms
applications?
Shared members of classes (AKA fields in Modules) live from their first
usage til the application's end.
How do i navigate from one form to another
form class? (example me.hide() and form2.show)


Write your own Sub Main:

Sub Main
Dim F as Form1
f.Show
Application.Run
End Sub

In Form1:
Dim f2 as Form2
f2 = New Form2

Me.Hide
f2.Show

--
Armin

Nov 20 '05 #3
CSP
Actually i did try both solutios, but unable to hide the
form1. And i got into a problem of showing two form at the
same time. So i used visible property of form1 as false to
get rid of its visibility. I think i m missing something
here...anyways i have another question. If i have nearly
40 to 50 forms in an application..hiding all these form
not going to create any problem in the application, right?
TIA
CSP
-----Original Message-----
i am a newbie to .net programming, i am having problem
with global data and form instanciation. My questions are
How do i maintain global data in windows forms
applications? How do i navigate from one form to another
form class? (example me.hide() and form2.show)
TIA
CSP
.

Nov 20 '05 #4

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

Similar topics

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...
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...
6
by: MechSoft | last post by:
Hi, I am new to C++ from C, I am a bit confused about using global objects in C++. I have a program that need to share some data(held in classes) between files, and of course I thought about using...
5
by: WJ | last post by:
I am attempting to use the Global.Asax to store my user's configuration. Here is the concept: 1. User logs on into the site using Form Authentication. 2. I capture the user Credential, verify it...
41
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
15
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for...
4
by: wakun | last post by:
Hi there, I have been using C for years. For some project I've done times ago, I always need to share variable between modules. The structure of my project is illustrated as follow /* global.h...
23
by: David Colliver | last post by:
Hi, using c#, 1.1 I know that we are not supposed to use global variables etc. in c# I am having a problem, but not sure how to resolve. I did have another post here, but may have over...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.