Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Arraylist ideas (http://www.programmingforums.org/showthread.php?t=14634)

Sil3ncer7 Nov 28th, 2007 9:36 AM

Arraylist ideas
 
I am trying to pull a value(9 digit number) from a text box then run it through an array and each run... Then list the array in a list box..

:

using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Labelapp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void cmdProcess_Click(object sender, EventArgs e)
        {
          for (long i = txtstart; i <= txtend; i++)
          lstList.Item.Add(i)
        }
    }
}



But its not running through. It keeps inserting "0" in the lstbox

Any ideas?

Infinite Recursion Nov 28th, 2007 10:04 AM

Re: Arraylist ideas
 
How are you defining txtstart and txtend?

"EventArgs e" should be "System.EventArgs e"

"lstList.Item.Add()" should be "lstList.Items.Add()"

Not sure exactly what you are looking for, but maybe this will help. I suppose it depends on what you expect to be in your array.
This code takes a nine digit number, pushes it to a string to reference its elements, then reads each element into the listbox.


:

        private void cmdProcess_Click(object sender, System.EventArgs e)
        {
            long num = 123456789;
            string n = num.ToString();

            for (int i = 0; i < 9; i++)
                lstList.Items.Add(n[i]);
        }


Sil3ncer7 Nov 28th, 2007 10:10 AM

Re: Arraylist ideas
 
Quote:

Originally Posted by Infinite Recursion (Post 137747)
How are you defining txtstart and txtend?

What do you mean? i guess they would be int cause theyd be a 9 digit number????

Sil3ncer7 Nov 28th, 2007 10:16 AM

Re: Arraylist ideas
 
So, if I were to have a txtbox to enter in that 9 digit number you would just use
long num = val txtStart??

Infinite Recursion Nov 28th, 2007 10:49 AM

Re: Arraylist ideas
 
What are the values of txtstart and txtend when you are entering the for loop? I didn't see where they were defined in code. If they were just referencing the start and end of the nine digit number then use 0 for the start and 8 for the end of your loop like I did. Or was it a range from one nine digit number to another nine digit number?

long num = Convert.ToInt32(txtStart.Text);

Sil3ncer7 Nov 28th, 2007 10:53 AM

Re: Arraylist ideas
 
Here is what I am working on.. if this is a little more understanding
http://i81.photobucket.com/albums/j2...7/untitled.jpg

you put in say 3216510001

and you supply the end at say 3216510005

so itll display in the lstList

3216510001
3216510002
3216510003
3216510004
3216510005

etc

mbd Nov 28th, 2007 11:24 AM

Re: Arraylist ideas
 
txtStart.Text would be a string representation of the text the user entered in that box. int.Parse(txtStart.Text) would return an integer representation of that text if it was formatted properly. If it was not formatted properly, it would throw a FormatException.

Infinite Recursion Nov 28th, 2007 2:29 PM

Re: Arraylist ideas
 
Try this...

:

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

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void cmdProcess_Click_1(object sender, System.EventArgs e)
        {
            long start = Convert.ToInt64(txtStart.Text);
            long stop = Convert.ToInt64(txtEnd.Text);

            for (long i = start; i <= stop; i++)
                lstList.Items.Add(i.ToString());
        }
    }
}


Sil3ncer7 Nov 28th, 2007 3:08 PM

Re: Arraylist ideas
 
Quote:

Originally Posted by Infinite Recursion (Post 137759)
Try this...

:

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

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void cmdProcess_Click_1(object sender, System.EventArgs e)
        {
            long start = Convert.ToInt64(txtStart.Text);
            long stop = Convert.ToInt64(txtEnd.Text);

            for (long i = start; i <= stop; i++)
                lstList.Items.Add(i.ToString());
        }
    }
}



Sweet thanks. I started getting the out of range handler so I was gonna switch it from the int 32 to int64.. Thanks for the help.

Infinite Recursion Nov 28th, 2007 3:17 PM

Re: Arraylist ideas
 
Yeah... my fault for mentioning the int32 without testing it. I caught that problem and switched to int64.


All times are GMT -5. The time now is 3:33 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC