473,548 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing a number of integers between forms

I need to pass 4 integers between two forms but am having trouble
passing more than one.I am hoping to use the contructor approach as i
need the variables straight away

Any help would be great

thanks

Nick

Dec 7 '06 #1
4 2660
Tell me the problem, the given explaination is not detail enough but yes you
can pass any number of parameters via a user defined constructor to any
amount of forms :-)

Nirosh.

<ni*********@ho tmail.comwrote in message
news:11******** **************@ 73g2000cwn.goog legroups.com...
>I need to pass 4 integers between two forms but am having trouble
passing more than one.I am hoping to use the contructor approach as i
need the variables straight away

Any help would be great

thanks

Nick

Dec 7 '06 #2
What does your consturctro look like?

I think a good idea would be to pass array of integres to other form, so the
number of integers shouldn't be a problem.
<ni*********@ho tmail.comwrote in message
news:11******** **************@ 73g2000cwn.goog legroups.com...
>I need to pass 4 integers between two forms but am having trouble
passing more than one.I am hoping to use the contructor approach as i
need the variables straight away

Any help would be great

thanks

Nick

Dec 7 '06 #3
I need to get int1 int2 and int3 from

"private void button1_Click(o bject sender, System.EventArg s e)" in
form1 to

public form2();

In form2 i will need to use each variable in public form2 rather than a
specific object further down the code

i was previously using the contructor tutorial i found here

http://www.codeproject.com/useritems...ween_forms.asp

but could not work out how to send multiple integers

Im sorry if this is still pretty vague! im still getting the hang of
this!

Champika Nirosh wrote:
Tell me the problem, the given explaination is not detail enough but yes you
can pass any number of parameters via a user defined constructor to any
amount of forms :-)

Nirosh.

<ni*********@ho tmail.comwrote in message
news:11******** **************@ 73g2000cwn.goog legroups.com...
I need to pass 4 integers between two forms but am having trouble
passing more than one.I am hoping to use the contructor approach as i
need the variables straight away

Any help would be great

thanks

Nick
Dec 7 '06 #4
ni*********@hot mail.com wrote:
I need to get int1 int2 and int3 from

"private void button1_Click(o bject sender, System.EventArg s e)" in
form1 to

public form2();

In form2 i will need to use each variable in public form2 rather than a
specific object further down the code

i was previously using the contructor tutorial i found here

http://www.codeproject.com/useritems...ween_forms.asp

but could not work out how to send multiple integers

Im sorry if this is still pretty vague! im still getting the hang of
this!
So create a constructor for form2 that either takes in four integers, an int
array, or possibly a struct that has the integers as properties. The last
approach gives you the most flexibility in that you can add additional items
to the struct without changing your constructor signature. But use
whichever best fits the needs of your particular problem. Exs:

public Form2()
{
InitializeCompo nent();
}

// constructor that takes in four ints
public Form2(int val1, int val2, int val3, int val4) : this()
{
// set values based on ints passed in
control1.Value = int1;
control2.Values = int2;
//etc...
}

// constructor that takes an int[]
public Form2(int [] vals) : this()
{
control1.Value = vals[0];
control2.Value = vals[1];
//etc...
}

// create a struct to be used for passing data into the form
// refine to have private fields with public accessors
public struct Form2Data
{
public int val1;
public int val2;
public int val3;
public int val4;
}

// constructor that takes in the data in a struct
public Form2(Form2Data data) : this()
{
control1.Value = data.val1;
control2.Value = data.val2;
//etc...
}

--
Tom Porterfield

Dec 7 '06 #5

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

Similar topics

1
3162
by: Paul | last post by:
Hello, I've been experimenting with PHP 5's SOAP extension and I've run into this problem: methods that have XSD_LONG parameters fail if a big integer is passed. Unsigned big integers are always converted to (negative) signed integers when they are put in the SOAP message: For example, this produces the correct result: $this->personID...
5
34346
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses the actual function call. I will post the code below of the structure, the prototype and and function call and if someone can explain this I would...
12
6516
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html ...
58
10073
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
12
2786
by: Joel | last post by:
Hi all, Forgive me if I've expressed the subject line ill. What I'm trying to do is to call a c++ function given the following: a. A function name. This would be used to fetch a list of function descriptors for the overloaded functions of that name. A function descriptor would contain the address of the function to be called, and a...
8
2109
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects, each requiring a call to that method to fulfill their purpose. There could be 200, there could be more than 1000. That is a lot of references passed...
1
3104
by: Darsin | last post by:
Hi all, I am a new programmer to C# and i am having a following problem. I want to make a single method which takes a variable length array and display it contents. i have defined the method as: public void DisplayVals(params object objArray) { foreach (object o in objArray) Console.WriteLine(o.ToString()); }
3
3778
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes a variant containing an array, and interop expects a parameter of type object if you are passing a variant (you are expected to cast it to the...
29
2177
by: Richard Harter | last post by:
There is probably a simple way to do what I want but I don't see it. Any suggestions are welcome. Suppose I have a function foo with an argument that can be any of several types and that I want to use a union for that argument. In a header file there is the following: #define VAL_ALT union urt_value_alt .....
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7444
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...
0
7711
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, 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. ...
1
7467
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7805
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 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...
0
6039
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1932
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
0
755
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.