473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sharing variable between forms

I have two forms and wish to share some information between them.

I declare the array as Shared in the fisrt class but cannot reference it in the second class.
code is:-
Public Class DataEntry1
Inherits System.Windows.Forms.Form
Shared deArray(10) As String

#Region " Windows Form Designer generated code "
…

Private Sub Yes_Click(ByVal sender As System.Object ......
deArray(6) = "Yes"
End Sub

Public Class DataEntry2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
…

Private Sub yes1_Click(ByVal sender As System.Object, ....
deArray(4) = "Maybe"
End Sub
--------------------------------------------------
deArray(4) is "Not Declared.

Thanks for yoiur help.
Nov 20 '05 #1
2 2866
You have to qualify shared member with class name:

DataEntry1.deArray(...)

when accessing it from non-declaring classes

HTH
Alex
"gavin" <ga***@discussions.microsoft.com> wrote in message
news:DF**********************************@microsof t.com...
I have two forms and wish to share some information between them.

I declare the array as Shared in the fisrt class but cannot reference it in the second class. code is:-
Public Class DataEntry1
Inherits System.Windows.Forms.Form
Shared deArray(10) As String

#Region " Windows Form Designer generated code "
:

Private Sub Yes_Click(ByVal sender As System.Object ......
deArray(6) = "Yes"
End Sub

Public Class DataEntry2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
:

Private Sub yes1_Click(ByVal sender As System.Object, ....
deArray(4) = "Maybe"
End Sub
--------------------------------------------------
deArray(4) is "Not Declared.

Thanks for yoiur help.

Nov 20 '05 #2
you can add a code module and declare those variables Public
or pass params ByVal

"gavin" <ga***@discussions.microsoft.com> wrote in message
news:DF**********************************@microsof t.com...
I have two forms and wish to share some information between them.

I declare the array as Shared in the fisrt class but cannot reference it in the second class. code is:-
Public Class DataEntry1
Inherits System.Windows.Forms.Form
Shared deArray(10) As String

#Region " Windows Form Designer generated code "
.

Private Sub Yes_Click(ByVal sender As System.Object ......
deArray(6) = "Yes"
End Sub

Public Class DataEntry2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
.

Private Sub yes1_Click(ByVal sender As System.Object, ....
deArray(4) = "Maybe"
End Sub
--------------------------------------------------
deArray(4) is "Not Declared.

Thanks for yoiur help.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 20 '05 #3

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

Similar topics

4
by: DaveE | last post by:
I have a project consisting of two forms and a class that I created. The class, called Project, has several properties and a method. Form1 instantiates my Project class and populates the...
1
by: baylor | last post by:
Are there are any best practices or guidance on how to share an object between the Web world and the non? Here's my situation: i have one object (a security profile containing IPrincipal + some...
2
by: Red Green | last post by:
I am trying to switch to C# from Delphi and I am having some trouble finding some information. What I need to do should be simple but I have been through a dozen books and done web searches that...
2
by: Denis_dh | last post by:
Hi, I have a set of Forms and wish to have a varible used by more than one of them but can't seem to figure where to initialise it or how to acess it if I initialise it in a different form...
3
by: Robert W. | last post by:
I'm embarking on a project that will have both a desktop application and a Pocket PC application. It seems logical to have as much code as possible sitting in a shared project, which would be...
0
by: Nabani Silva | last post by:
Hi, hope someone could help I need to share session state (and contents) through differente web applications. I'm trying to get it done by using StateServer session state, below I paste code...
3
by: Chris Thunell | last post by:
I have 2 forms, on 1 form i use the wizards to create a strong typed dataset with tables from an SQL database... and from that i can do stuff like: me.daEmployee.fill(me.dataset11.tblEmployee) ...
11
by: Nick | last post by:
Hello, Please pardon my ignorance as this is something I should know, but I'm a little unclear. I have an MDI based app. It is setup so the user opens a file and the main child form is created....
3
by: Al_C | last post by:
As mentioned earlier I've been away from coding for about 5 years. Know I know why :( I've been trying to work out a critical detail, hard to do on Thanksgiving ;) Push a button on form1, form2...
0
marktang
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,...
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,...
1
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: 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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.