Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 28th, 2007, 2:23 PM   #11
Sil3ncer7
Programmer
 
Join Date: Sep 2007
Posts: 33
Rep Power: 0 Sil3ncer7 is on a distinguished road
Re: Arraylist ideas

Really, Thanks again. I was close, but there always is that finishing touch that you forget.. Thanks

Now I am going to work on a printing function.. Is there any good sites for creating a printing onto a template?

I found this http://www.devarticles.com/c/a/C-Sha...Using-C-sharp/

so hopefully it helps..
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards....
Sil3ncer7 is offline   Reply With Quote
Old Nov 28th, 2007, 6:11 PM   #12
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: Arraylist ideas

I'd use long.TryParse() for checking the input for validity. Exception handling seems to be overkill for something like this. You'd get something that's similar to this:
c# Syntax (Toggle Plain Text)
  1. private void btnProcess_Click(object sender, EventArgs e)
  2. {
  3. long start, end;
  4. lstList.Items.Clear();
  5. // long.TryParse() tries to convert a string to a long, and if
  6. // successful, it fills in the passed-in variable and returns
  7. // true; otherwise it returns false. thus, if both textboxes
  8. // contain text that can be converted to longs, we can process
  9. // the numbers, and if not, we inform the user of the error.
  10. if (long.TryParse(txtStart.Text, out start) &&
  11. long.TryParse(txtEnd.Text, out end))
  12. for (long x = start; x <= end; ++x)
  13. lstList.Items.Add(x);
  14. else
  15. MessageBox.Show("You must enter integers in both text boxes.",
  16. "Error!", MessageBoxButtons.OK,
  17. MessageBoxIcon.Error);
  18. }
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Nov 28th, 2007, 9:30 PM   #13
Alias
Newbie
 
Join Date: Oct 2007
Posts: 29
Rep Power: 0 Alias is on a distinguished road
Re: Arraylist ideas

Personally I would keep the handling in a different area in order to not cause uncomfortability to the user.

By making the textbox(es) only accept numeric characters, which I presume you are already doing, and validating the input as entered it can easily be acheived as such:

        private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar)) { }
            else if (e.KeyChar == '\b') { }
            else { e.Handled = true; }
        }

        private void textBox_TextChanged(object sender, EventArgs e)
        {
            long value;
            if (!long.TryParse(textBox.Text, out value))
                textBox.Text = long.MaxValue.ToString();
        }
Alias is offline   Reply With Quote
Old Nov 28th, 2007, 9:56 PM   #14
Sil3ncer7
Programmer
 
Join Date: Sep 2007
Posts: 33
Rep Power: 0 Sil3ncer7 is on a distinguished road
Re: Arraylist ideas

Well yea.. I want to make sure they dont input
1.) Any more that 9 digits...
2.) No letters
3.) Nothing difference in numbers over 5,000
GOOD ex. (start)3216510001 - (end)321651501
BAD ex. (start)3216510001 - (end)321659009

Just to eliminate errors...
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards....
Sil3ncer7 is offline   Reply With Quote
Old Nov 28th, 2007, 11:58 PM   #15
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: Arraylist ideas

Quote:
Originally Posted by Sil3ncer7
Well yea.. I want to make sure they dont input
1.) Any more that 9 digits...
This is the easiest. Set the MaxLength property of txtStart and txtEnd to 9; this will prevent the user from adding more. You can do it either in the designer, or in code. It amounts to the same thing.
Quote:
Originally Posted by Sil3ncer7
2.) No letters
This is tougher. It's easy to validate the input and, if invalid, display some error message as I did in my example. If you actually want to make it impossible to enter digits, you can try various approaches. One is to override the KeyPress event, test the character, and set the Handled property of the EventArgs object to true if it's not valid (valid being a digit or backspace, probably). However, there are problems with this approach, as the user can get invalid data into the control in other ways (cut-and-paste comes to mind). Thus, your best bet would be to create a new control, and define the behavior in such a manner as to always ensure valid data, but this is probably far beyond the scope of your exercise.
Quote:
Originally Posted by Sil3ncer7
3.) Nothing difference in numbers over 5,000
GOOD ex. (start)3216510001 - (end)321651501
BAD ex. (start)3216510001 - (end)321659009
Again, this is harder than it sounds if you want the data continuously validated. The easiest course of action is to validate it when the user clicks the button, but you need to decide if a difference >5000 is an error, or if the results get truncated (and if they get truncated, which numbers get added to the list). Assuming the user entered two numbers, and you've since converted them to numbers with long.TryParse() or equivalent, you can do something like this:
c# Syntax (Toggle Plain Text)
  1. // if start is greater than end, swap the two
  2. if(start > end)
  3. {
  4. long temp = start;
  5. start = end;
  6. end = temp;
  7. }
  8. long difference = end - start > 5000 ? 5000 : end - start;
  9. for(long x = 0; x<=difference; ++x)
  10. lstList.Items.Add((start + x).ToString());
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Nov 29th, 2007, 5:00 AM   #16
Alias
Newbie
 
Join Date: Oct 2007
Posts: 29
Rep Power: 0 Alias is on a distinguished road
Re: Arraylist ideas

I thought my post made a pretty clear example of what you go on to explain lectric, my apologies if it was not concise enough.

Textbox controls can also be configured so that copying/pasting is not possible, creating a custom control seems a bit OTT as you say, lectric, but disabling context menus etc is alot easier.

But here's an idea, the NumericUpDown control may be best suited.
Alias is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList Start Index kruptof C# 8 Sep 2nd, 2007 10:20 AM
Problem with an ArrayList Twilight C# 2 Apr 25th, 2006 1:15 PM
ArrayList and MSDN Writlaus C++ 13 Apr 5th, 2006 3:27 AM
ArrayList Troubles crawforddavid2006 Java 17 Jan 10th, 2006 6:37 PM
Converting object to arraylist yusufozkay C# 1 Jul 18th, 2005 8:08 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:44 AM.

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