Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 4th, 2012, 02:41 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code validation

HI everyoone
I'm new in C# and i have one question. I should write a code that validates a text that should be: 7 digits in 6 rows,and should be separated by a space.Like this
1 2 3 4 5 6 7
0 8 9 7 1 3 9
4 5 6 9 7 2 1
6 9 2 0 5 6 6
.
.
.
I'm writting the code in Visual Studio 2008, windowsformapplication.
I have no idea how to write this, so plese help :) Thanks
Reply With Quote
  #2 (permalink)  
Old January 4th, 2012, 04:49 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code Validation

Hi Isabella,

You need to think about how you are going to get the data to be valiated into your program. Will it be manually input?, read from a file? or a database? Or it could be hard coded into the program.

It sounds like you created a new project from the Windows Form Application template. This will give you more than you need, but it also provide a way that you could add user input to the form to get your data.

The simpliest thing to do might be to add a button to your form. Double clicking the button in the design view will create a function to respond to a click of the button when running. You can put your validation code in this function.

From your description it sounds like you will be getting a series of strings. So you might be putting the data in an array as in

Code:
string[] MyData = new string[4];

MyData[0] = "1 2 3 4 5 6 7";
...
or a collection such as an ArrayList:

Code:
ArrayList MyData = new ArrayList();

MyData.Add("1 2 3 4 5 6 7");
...

Your code will need to parse each of the strings into individual digits.
You can take advantage of member functions of the string class like "Split" to do this.

You haven't specified what about the data to validate so I'll leave that up to you.

Hopefully, I've give you enough to get started. Come back with more questions when you have more done.
Reply With Quote
  #3 (permalink)  
Old January 4th, 2012, 05:32 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
This is manually input by a user. The user should enter the values(0-9, in 6 rows, separated by space) in a textBox and after he clicks on a button it should verify the input like I mentioned above. If it's wrong than it should pop up an error message. I know that this code should be in btn_Click function, but I I don't how to verify the input. Should I use the if statement or maybe the for loop? Thanks :)
Reply With Quote
  #4 (permalink)  
Old January 4th, 2012, 06:01 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code Validation

A TextBox control will contain an array of Lines if you allow more than one line in the TextBox. You need to itterate through the Lines array to get each string the user entered. You can use the "for" statement to do this.

You could use another "for" statement to parse each string, checking each character for either a space or a single digit integer.

If you are not familiar with how to use a "for" statement in C# you should look that up.

To determine if a single character is an integer you should read about the member functions of the Integer class.

You might get started here:
http://msdn.microsoft.com/en-us/libr...(v=VS.90).aspx
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding validation code in excel donsls Excel VBA 1 November 1st, 2008 01:37 AM
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Validation using Validation Framework kalyangvd Struts 1 January 2nd, 2008 06:53 AM
running example code from Ch 3 - Form Validation cshu BOOK: Professional Ajax ISBN: 978-0-471-77778-6 0 November 4th, 2006 05:52 AM



All times are GMT -4. The time now is 05:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.