Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Take a value from textbox and insert into an array - Newbie Question!

Status
Not open for further replies.

rihtx

IS-IT--Management
Feb 6, 2007
12
US
Hey everyone,

I am newbie to C# and VS.NET.

I am creating a very small windows application in visual studio 2003. I have single form (form1.cs) that has textboxes for the user to enter the balance, apr and monthly payment for 3 credit cards (9 text boxes).
I would like to create 3 arrays containing the values from each input category. This should be done in a separate class file.
Additional classes file will containing a method that will read the values in the apr array and sort them based on highest APR value, A method that will total calculate the average apr values and the sum of the balance values

How should I apporach this in .net?


 
Hi, and welcome, ... as you are new to the forums.

Reading your post and especially "This should be done in a separate class file", "A method that will..." makes my think that this is homework or like so (prohibited by the forum rules). Please tell me that i am wrong!

There are many ways to hold data in memory. Eg, in array(s), structs, classes, and/or a combination of them, etc. You choose what best fits you.


Regards.
 
Tipgiver,

Thanks for quick response. This is an instructor related project. I have carte blanche to create any program as long as I use visual studio. The arrays and methods are not required. I can pass the input values from the user in a console application, but not using visual studio. The methods are not a problem either, just background for you guys to better understand why I chose the arrays in a separate class. This is a debt reduction program.

Anyway all I am trying to do is to pass the input value from the textbox to the array and I have not found any documentation anywhere that specifically addresses this particular issue.

I respect the forum rules so please don't give advice if you feel the forum rules are applying to my post.
 
I respect the forum rules so please don't give advice if you feel the forum rules are applying to my post.

> There are many ways to hold data in memory. Eg, in array(s), structs, classes, and/or a combination of them, etc. You choose what best fits you.

I gave you an answer, although i had doubts.
Anyway let's go.
_________________________

In arrays, you can store data of the same type.

int[] arrayName= new int[2];
arrayName[0] = int.Parse(this.textBox1.Text);
arrayName[1] = int.Parse(this.textBox2.Text);


You said that you have 3 (balance, apr and monthly payment) X 3 textboxes.
You can have 3 arrays of size 3. The 1st will have balance, 2nd the apr and the 3rd the payment.

You can create something like:

struct Card
{
float balance;
int apr;
double payment;
}

and store there the info. (create a 3-dim array of the Card object)

Else, you can create a separate class file with its private variables and write public get/set properties to set and set the private vars.
 
One correction:

public struct Card
{
public float balance;
public int apr;
public double payment;
}

- The bold are to expose those variables outside the struct, ..so they can be used.
- The blue is just the modifier of the struct. If ommitted, then it will be private.
 
Tipgiver

Thanks for you advice. It works now!!.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top