Okay, so I have a main form which has a button for the user to add a new record. I have everything working except making sure the user enters appropriate values. I have it so a message box pops up the value is not valid, but it goes into an infinite loop. I am having a bitch of a time figuring out why. Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Record_Filer
{
public partial class NewRecord : Form
{
public string Mame { set; get; }
public string Genre { set; get; }
public string Date { set; get; }
public string Rating { set; get; }
public NewRecord()
{
InitializeComponent();
}
private void NewRecord_Load(object sender, EventArgs e)
{
txbName.Text = "";
txbGenre.Text = "";
txbDate.Text = "";
txbRating.Text = "";
Mame = "";
Genre = "";
Date = "";
Rating = "";
}
private void btnCancel_Click(object sender, EventArgs e)
{
txbName.Text = "";
txbGenre.Text = "";
txbDate.Text = "";
txbRating.Text = "";
Mame = "";
Genre = "";
Date = "";
Rating = "";
this.Hide();
}
private void btnSave_Click(object sender, EventArgs e)
{
int nameOK = 0; // selects the final closing of the process. ***not working correctly***
int genreOK = 0; // maybe a switch would be better?
int dateOK = 0;
int rateOK = 0;
int j = 0;
while (j == 0)
{
if (txbName.Text != "")
{
Mame = (txbName.Text); nameOK = 1;
}
else { MessageBox.Show("Please enter a DVD name"); nameOK = -1; }
if (txbGenre.Text != "")
{
Genre = (txbGenre.Text); genreOK = 1;
}
else { MessageBox.Show("Please enter a DVD genre"); genreOK = -1; }
int date = 0;
if (txbDate.Text != "")
{
date = Convert.ToInt32(txbDate.Text);
}
if ((txbDate.Text != "") && (date >= 1800) && (date <= 3000))
{
Date = (txbDate.Text); dateOK = 1;
}
else { MessageBox.Show("Please enter a DVD date between 1800 - 3000"); dateOK = -1; }
int rate = 0;
if (txbRating.Text != "")
{
rate = Convert.ToInt32(txbRating.Text);
}
if ((txbRating.Text != "") && (rate >= 1) && (rate <= 5))
{
Rating = (txbRating.Text); rateOK = 1;
}
else { MessageBox.Show("Please enter a DVD rating between 1 - 5"); rateOK = -1; }
if ((nameOK == 1) && (dateOK == 1) && (genreOK == 1) && (rateOK == 1))
{
j = 1; this.Close(); // ***** exits out and returns to main ... ****
}
}
}
}
}
Any help on what I'm doing wrong here?