1 Replies - 377 Views - Last Post: 03 March 2013 - 02:19 AM Rate Topic: -----

#1 cirustus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 16-February 13

validating and error checking

Posted 03 March 2013 - 12:53 AM

i have a 2d array but i am having trouble working out how to validate and error check my textbox's
they all have to contain numbers only but i cant get my head around it
any help would be appreciated.


    int day = int.Parse(textBox1.Text);
            int mon = int.Parse(textBox2.Text);
            int g = int.Parse(this.textBox3.Text);
            int h = a.GetUpperBound(0) - 1;
        
            for (int i = 0; i<=h; i++)
        {
            
        if (double.Parse (a[i,0]) == g)    
        {
            if (day >= 1 && mon == 1 || day <= 20 && mon == 1)
        


Is This A Good Question/Topic? 0
  • +

Replies To: validating and error checking

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: validating and error checking

Posted 03 March 2013 - 02:19 AM

First, if you are trying to enter a date, why not use a DateTimePicker control?

Second, use the Validating event on the control, validate the input and set the CancelEventArgs Cancel property to true if the input is good.

Lastly
int h = a.GetUpperBound(0) - 1;
for (int i = 0; i<=h; i++)


Why subtract one and use less than or equal when you can just take the value and use less than?
int h = a.GetUpperBound(0);
for (int i = 0; i < h; i++)
does the exact same thing :)/>/>

This post has been edited by JackOfAllTrades: 03 March 2013 - 04:13 AM
Reason for edit:: Fixed typo in code

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1