Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
AnswerRe: Encrypting String Pin
GuyThiebaut23-Jan-15 0:43
professionalGuyThiebaut23-Jan-15 0:43 
QuestionHow can I clear a file's content? Pin
kidult22-Jan-15 18:10
kidult22-Jan-15 18:10 
AnswerRe: How can I clear a file's content? Pin
Wendelius22-Jan-15 18:19
mentorWendelius22-Jan-15 18:19 
GeneralRe: How can I clear a file's content? Pin
kidult22-Jan-15 21:06
kidult22-Jan-15 21:06 
GeneralRe: How can I clear a file's content? Pin
Wendelius23-Jan-15 2:42
mentorWendelius23-Jan-15 2:42 
Questionc# validation Pin
Member 1135438622-Jan-15 13:51
Member 1135438622-Jan-15 13:51 
GeneralRe: c# validation Pin
PIEBALDconsult22-Jan-15 14:33
mvePIEBALDconsult22-Jan-15 14:33 
GeneralRe: c# validation Pin
Member 1135438622-Jan-15 17:17
Member 1135438622-Jan-15 17:17 
input products made on each day then get the day and week produced only out of the array
It needs to be an input box as per assignment I just am doing my head in validating as its a project the specs for it i tried the combo box :P i cant find anything in the source material to guide as to what my instructors want...the advice they give is that the string be at least 3 letters and that when i run it the days inputed into the box must be monday tuesday wednedsay thursday or friday and no numbers ... if there is an easier way im up to learning that too
I can paste the whole code
C#
private void btnInputBox_Click(object sender, EventArgs e)
       {

           int[,] toyArray = new int[4, 5]; ////4,5
           var totalToys = 0;//variable to hold and  accumulate the total

           string[] dayNameArray = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
           string specDay;
           int specWeek;
           string val = "";
           int specDayTotal;
           string Output = "";
           string Output1 = "Retrieve Products produced On A specific day";
           string Output2 = " Products produced On That day are:";
           string Output3 = "Sum of All Products Made = ";
           int num = 0;
           int Days=0;
           string dOW = "";
           for (int row = 0; row < toyArray.GetLength(0); row++)//enters loop to store data to array ,starts first row
           {
               for (int Col = 0; Col < toyArray.GetLength(1); Col++)//starts first column...
               {

                   val = Microsoft.VisualBasic.Interaction.InputBox("How Many Toys Made for Week:" + (row + 1) + "  " + dayNameArray[Col] + ":  ");//gets the string value of number entered
                   try
                   {
                       while (!(int.TryParse(val, out num)))//converts the string to a int to validate.. if the number IS NOT a Number eg.letter
                       {
                           MessageBox.Show("Not a valid number, try again.");//then sends this message
                           val = Microsoft.VisualBasic.Interaction.InputBox("How Many Toys Made for Week:" + (row + 1) + "  " + dayNameArray[Col] + ":  ");//re enter a number
                       }
                   }
                   catch (Exception)
                   {
                       MessageBox.Show("Value entered is not in a valid format");//exception message
                   }
                   toyArray[row, Col] = num;//else it stores this number for the array

               }//goes out to check next col of the row  once all columns done it goes to nEXT Row

           }
           //once ALL Rows checked it comes outta loop


           for (int row = 0; row < toyArray.GetLength(0); row++)//enters new loop to write data
           {

               for (int Col = 0; Col < toyArray.GetLength(1); Col++)
               {


                   Output += "          " + toyArray[row, Col] + "          ";
                   totalToys += toyArray[row, Col];

               }

               Output += "  " + "\r\n" + "";//first row checked sets a space between rows

           }

           specDay = Microsoft.VisualBasic.Interaction.InputBox("What Day Would You Like To Check:");// to find specific toys made on a specific day
           string sPattern = "^(Mon|(T(ues|hurs))|Fri)(day|\\.)?$|Wed(\\.|nesday)?$|T((ue?)|(hu?r?))\\.?$";//checks the entered data is a viable string(\\Length{3}?$)

           int result = Array.BinarySearch(dayNameArray, specDay, StringComparer.OrdinalIgnoreCase);

               if (System.Text.RegularExpressions.Regex.IsMatch(specDay, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
               {

                   for (int dayCounter = 0; dayCounter < dayNameArray.GetLength(0); dayCounter++)//start loop number daycounter at 0 ,day counter of the length of array which will be 4(0-4) then add one to the count
                   {
                       if (dayNameArray[dayCounter] == specDay) // Compare specDay to the current index of the dayNameArray.If it finds a match
                       {
                           Days = dayCounter;//finds  the count and declares it as an int(eg. monday matches 0)
                       }
                   }

           }
           else
           {
               MessageBox.Show("Not A valid Day Of Week");
               specDay = Microsoft.VisualBasic.Interaction.InputBox("What Day Would You Like To Check:");
           }

           specWeek = Int32.Parse(Microsoft.VisualBasic.Interaction.InputBox("What week Would You Like To Check:"));
               try
               {
                   while (!(specWeek <= 4)&& !(specWeek == num))//converts the string to a int to validate.. if the number IS NOT a Number eg.letter
                   {
                       MessageBox.Show("Not a valid number, try again.");//then sends this message
                       specWeek = Int32.Parse(Microsoft.VisualBasic.Interaction.InputBox("What week Would You Like To Check:"));//re enter a number
                   }
               }
               catch (Exception)
               {
                   MessageBox.Show("Must Be 1 to 4");//exception message

               }
           int Week = specWeek-1;


           specDayTotal = toyArray[Week, Days];

           txtOutput.Text += "          " + "Monday       Tuesday       Wednesday        Thursday        Friday  " + "\r\n" + Output + "         " + Output1 + "\r\n" + "   " + specDay + "    Week " + (Week+1) + "\r\n" + Output2 + "   =  " + specDayTotal + "\r\n" + Output3 + totalToys;
           }

       }

AnswerRe: c# validation Pin
Mycroft Holmes22-Jan-15 15:51
professionalMycroft Holmes22-Jan-15 15:51 
GeneralRe: c# validation Pin
Member 1135438622-Jan-15 17:15
Member 1135438622-Jan-15 17:15 
GeneralRe: c# validation Pin
PIEBALDconsult22-Jan-15 18:42
mvePIEBALDconsult22-Jan-15 18:42 
GeneralRe: c# validation Pin
Member 108362351-Feb-15 20:05
Member 108362351-Feb-15 20:05 
QuestionGiving a property a value when it lacks set-method? Pin
Member 1139440322-Jan-15 2:09
Member 1139440322-Jan-15 2:09 
AnswerRe: Giving a property a value when it lacks set-method? Pin
OriginalGriff22-Jan-15 2:51
mveOriginalGriff22-Jan-15 2:51 
GeneralRe: Giving a property a value when it lacks set-method? Pin
Member 1139440322-Jan-15 3:55
Member 1139440322-Jan-15 3:55 
GeneralRe: Giving a property a value when it lacks set-method? Pin
Richard Deeming22-Jan-15 4:25
mveRichard Deeming22-Jan-15 4:25 
GeneralRe: Giving a property a value when it lacks set-method? Pin
Member 1139440324-Jan-15 3:29
Member 1139440324-Jan-15 3:29 
GeneralRe: Giving a property a value when it lacks set-method? Pin
BillWoodruff22-Jan-15 5:11
professionalBillWoodruff22-Jan-15 5:11 
Questioni want code for read data from hyperterminal Pin
Member 1135275122-Jan-15 1:09
Member 1135275122-Jan-15 1:09 
AnswerRe: i want code for read data from hyperterminal Pin
Manfred Rudolf Bihy22-Jan-15 1:33
professionalManfred Rudolf Bihy22-Jan-15 1:33 
AnswerRe: i want code for read data from hyperterminal Pin
OriginalGriff22-Jan-15 2:53
mveOriginalGriff22-Jan-15 2:53 
QuestionDefragmentor in c# Pin
Anoop Mishra21-Jan-15 23:42
Anoop Mishra21-Jan-15 23:42 
AnswerRe: Defragmentor in c# Pin
harold aptroot21-Jan-15 23:46
harold aptroot21-Jan-15 23:46 
QuestionAuto Update Sql Database Schema Pin
Zeyad Jalil21-Jan-15 20:32
professionalZeyad Jalil21-Jan-15 20:32 
AnswerRe: Auto Update Sql Database Schema Pin
Mycroft Holmes21-Jan-15 20:42
professionalMycroft Holmes21-Jan-15 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.