473,394 Members | 1,641 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,394 software developers and data experts.

how to pass array between 2 forms

2
hey everyone

i want to know how u can pass an array between multiple forms in vb.net

like example for code

form2
public test(2) as string

test(0) = "test1"
test(1) = "test2"
test(2) = "test3"

form1
how can i get the value of my array test(1) of form2 ???
txtTest.text = ................................
Nov 4 '09 #1
4 5830
tlhintoq
3,525 Expert 2GB
It might just be cleaner to put it in your Program.cs as public then any form can access it along these lines.

Program.MyArray[3] for example
Nov 4 '09 #2
Araatn
2
how do u mean ?? bc its my second year of vb.net and multiple forms is all new to me
Nov 4 '09 #3
tlhintoq
3,525 Expert 2GB
An object created with a method has a scope of life only as large as the method.
If you create an object outside of a method then it has a scope of life as large as the class that it is in.
So if you create an object inside the Program class then it exists as long as the class Program exists.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows.Forms;
  4. using System.Drawing;
  5. using System.Threading;
  6. using System.Data;
  7. using System.ComponentModel;
  8. using System.Reflection;
  9. using System.Security.Permissions;
  10. using Microsoft.Win32;
  11.  
  12. namespace MyAmazingProgram
  13. {
  14.     static class Program
  15.     {
  16.         public static string[] MyStringArray;// Visible to all forms
  17.  
  18.         /// <summary>
  19.         /// The main entry point for the application.
  20.         /// </summary>
  21.         [STAThreadAttribute]
  22.         static void Main(string[] commandLine)
  23.         {
  24.             Control.CheckForIllegalCrossThreadCalls = false;
  25.             Application.EnableVisualStyles();
  26.             //Application.SetCompatibleTextRenderingDefault(true);
  27.             App myApp = new App();
  28.             myApp.Run(commandLine);
  29.         }
  30.     }
  31.  
In this example "MyStringArray" is accessable to any form in your project by referencing it through the class it is a part of: "Program"

So inside Form 1 you could:

Expand|Select|Wrap|Line Numbers
  1. string ThirdItem = Program.MyStringArray[2];
  2.  
Nov 4 '09 #4
tlhintoq
3,525 Expert 2GB
bc its my second year of vb.net and multiple forms is all new to me
So in more than a year of class plus whatever time you spend on your own playing and experimenting with this you've never created an application with more than one form? <stunned>

Get your money back on the tuition and go to the local book store. Buy a couple books of "Programming VB in 21 days", "Visual Basic in 15 minutes a day" and so on. You'll teach yourself more out one of those books in a week, than you learned in class in the first year.
Nov 4 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Peter Mullen | last post by:
Whew, it's been a while since I posted. Fogive me all for I have... anyway. I would like to be able to write a method of an object that could accept a string and set the corresponding form. ...
8
by: Brian F | last post by:
Exactly what the subject says. I have an ASP page that I want my C# windows application to open in Internet Explorer, and if possible have it send along a list of values from a list box. Thank you.
4
by: =?Utf-8?B?bmlja25hbWU=?= | last post by:
I have the following xml Schema: “<?xml version="1.0" encoding="Windows-1252"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
3
by: Troy | last post by:
I have a dilemma where I am creating a dynamic two dimensional array and filling it with information from a .csv file. Unfortunately, later when I try to call that information back from the array...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
3
by: swetha123 | last post by:
hello, I don't know how to use cookies please help me in this I am using the dream weaver cs4 I designed the navigation bar to my page using dream weaver cs4 navigation bar contains...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
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...
0
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...

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.