473,508 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type scope confusion.

Hello everyone.

I have a project at the moment which is working fine. I originally
coded my code in form1.cs, as this was the default code file generated
by Visual Studio. However now i'm trying to organise it better, so have
renamed the file to ChooseWindow and chose the autorename feauture, and
everything works fine.

I have just added a second form which will become my primary form
eventually, and I will call the original form (ChooseWindow) from this
new primary form. The problem i have is that the array list is setup in
the original form and I cant access it in the new form I have just
created. I need to be able to access this arraylist in both code files.
How do i declare it so that I can access it in both code files and not
just the original ChooseWindow code file?

Thanks very much,

Gary.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SHDocVw;

namespace InternetExplorerInterface
{
public partial class Choosewindow : Form
{
public Choosewindow() // Pull up the form
{
InitializeComponent();
}

ArrayList ar = new ArrayList();

}

Dec 1 '06 #1
4 1144
Thanks very much, i'll look into what you suggested right away.

The array list is used to store all open internet explorer window
objects. This in turn is used to populate a listview. However I only
need to give the user an option of selecting which window to work with
if there is more than one explorer window open. So, I have created
another form and will only call this choosewindow form if their is more
than one internet explorer window.

In order to check how many explorer window objects are in the
arraylist, i need to be able to check it's size from the new form i've
just created.

Now i dont know if i should build the array in my new form, and then
access it in the original choosewindow form, or if i should keep it as
it is in the choosewindow form, and just change it's access so i can
access it in my new form.

Hope that explains it a bit better,

Thanks,
Gary.
Ciaran O''Donnell wrote:
You could declare a public property on the choosewindow for to access it. You
would however need to have an instance of the form to use it. Otherwise you
could declare it and the property static which would stop you needing an
instance.
What is the arraylist for, it would help to know to recommend the best
coarse of action.
--

Ciaran O''Donnell
http://wannabedeveloper.space.live.com
"ga********@myway.com" wrote:
Hello everyone.

I have a project at the moment which is working fine. I originally
coded my code in form1.cs, as this was the default code file generated
by Visual Studio. However now i'm trying to organise it better, so have
renamed the file to ChooseWindow and chose the autorename feauture, and
everything works fine.

I have just added a second form which will become my primary form
eventually, and I will call the original form (ChooseWindow) from this
new primary form. The problem i have is that the array list is setup in
the original form and I cant access it in the new form I have just
created. I need to be able to access this arraylist in both code files.
How do i declare it so that I can access it in both code files and not
just the original ChooseWindow code file?

Thanks very much,

Gary.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SHDocVw;

namespace InternetExplorerInterface
{
public partial class Choosewindow : Form
{
public Choosewindow() // Pull up the form
{
InitializeComponent();
}

ArrayList ar = new ArrayList();

}
Dec 1 '06 #2
Also i tried to check your domain out wannabedevloper, but it isn't
accesible!

Dec 1 '06 #3
I suspect that at some point you will want to populate that arraylist and
use its contents :=) A better approach would be to create a separate class
that exposes a public method which populates the arraylist. Then you can
create an instance of that class and call the arraylist method from whatever
form you wish.

public YourClass()
{
}

public ArrayList GetWhatever()
{
ArrayList al = new ArrayList();
try
{
... populate arraylist
}
catch (Exception ex)
{
throw ex;
}
return al;
}

<ga********@myway.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
Hello everyone.

I have a project at the moment which is working fine. I originally
coded my code in form1.cs, as this was the default code file generated
by Visual Studio. However now i'm trying to organise it better, so have
renamed the file to ChooseWindow and chose the autorename feauture, and
everything works fine.

I have just added a second form which will become my primary form
eventually, and I will call the original form (ChooseWindow) from this
new primary form. The problem i have is that the array list is setup in
the original form and I cant access it in the new form I have just
created. I need to be able to access this arraylist in both code files.
How do i declare it so that I can access it in both code files and not
just the original ChooseWindow code file?

Thanks very much,

Gary.

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SHDocVw;

namespace InternetExplorerInterface
{
public partial class Choosewindow : Form
{
public Choosewindow() // Pull up the form
{
InitializeComponent();
}

ArrayList ar = new ArrayList();

}

Dec 20 '06 #4

ga********@myway.com wrote:
Thanks very much, i'll look into what you suggested right away.

The array list is used to store all open internet explorer window
objects. This in turn is used to populate a listview. However I only
need to give the user an option of selecting which window to work with
if there is more than one explorer window open. So, I have created
another form and will only call this choosewindow form if their is more
than one internet explorer window.

In order to check how many explorer window objects are in the
arraylist, i need to be able to check it's size from the new form i've
just created.

Now i dont know if i should build the array in my new form, and then
access it in the original choosewindow form, or if i should keep it as
it is in the choosewindow form, and just change it's access so i can
access it in my new form.
It sounds to me as though the new form, Form2, will be called from the
original form. Is that true? Or is it the other way around? I'm a
little foggy on how the forms are supposed to be related.

Dec 21 '06 #5

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

Similar topics

3
3603
by: Tony Johansson | last post by:
Hello Experts!! When you instansiate varaibles(object) you can do so in four different scops which are. Within a block which is called Local or block scope . Within a function which is called...
51
4453
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
6
2678
by: S.Tobias | last post by:
I'm trying to understand how structure type completion works. # A structure or union type of unknown # content (as described in 6.7.2.3) is an incomplete type. It # is ...
5
3191
by: Sandra-24 | last post by:
Is there a way in python to add the items of a dictionary to the local function scope? i.e. var_foo = dict. I don't know how many items are in this dictionary, or what they are until runtime. ...
7
2098
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
14
2231
by: Alex | last post by:
I saw the topic of "wired code " about "point to array" and know a little about it. But I am still confused about the question below: I define a point to array "b" int (*b); then I locate the...
9
1358
by: garyusenet | last post by:
Hello I'm trying to get to grips with variable scope. I have a very basic programme i'm working on - and am once again being confused by scope of variables. I am just trying to write a new...
70
3289
by: garyusenet | last post by:
I'm using an example piece of code: - namespace Wintellect.Interop.Sound{ using System; using System.Runtime.InteropServices; using System.ComponentModel; sealed class Sound{ public static...
5
2220
by: somenath | last post by:
Hi All , I have one question regarding scope and lifetime of variable. #include <stdio.h> int main(int argc, char *argv) { int *intp = NULL; char *sptr = NULL;
0
7336
Oralloy
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,...
1
7063
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
5640
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
5059
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
3211
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
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
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 ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
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...

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.