I'm having problems in passing the values of the array.
I created an array in a class, then I instantiate it in frmMain(form1) then i put some values in the array(I signed up I put username and password in the array). frmMain should pass the values in the the array right?
My problem is when I instantiate the class(which holds the array) in frmProfile(form2) its like i never put some values in it.
In short, I want the array to be accessible in all forms. Do I need a constructor method?(something like get; set;?).
public class Tagasalo //this is the class i created
{
public String[,] array = new String[5, 2];
}
heres my code in frmMain(form1)
Tagasalo arr = new Tagasalo();
frmProfile profile = new frmProfile();
int row;
bool validInput = true;
int tries = 3;
public frmMain()
{
InitializeComponent();
}
public void btnSignUp_Click(object sender, EventArgs e)
{
if (txtUsernameS.Text.Trim() == String.Empty)
{
errorProvider1.SetError(txtUsernameS, "Please put a Username.");
}
else if (txtUsernameS.TextLength > 1 && txtUsernameS.TextLength < 4)
{
errorProvider1.SetError(txtUsernameS, "Your Username must have 4 or more characters.");
}
else
{
errorProvider1.Clear();
}
if (txtPasswordS.Text == String.Empty)
{
errorProvider2.SetError(txtPasswordS, "Please put a Password.");
}
else if (txtPasswordS.TextLength > 1 && txtPasswordS.TextLength < 6)
{
errorProvider2.SetError(txtPasswordS, "Your Password must have 6 or more characters.");
}
else
{
errorProvider2.Clear();
}
for (row = 0; row < 5; row++)
{
if (txtUsernameS.TextLength >= 4 && txtPasswordS.TextLength >= 6)
{
if (txtConfirmPassword.Text != txtPasswordS.Text)
{
errorProvider3.SetError(txtConfirmPassword, "Your Password does not match.");
}
else if (txtConfirmPassword.Text == txtPasswordS.Text)
{
if (arr.array[row, 0] == null && arr.array[row, 1] == null)
{
arr.array[row, 0] = txtUsernameS.Text;
arr.array[row, 1] = txtPasswordS.Text;
MessageBox.Show("Signed-Up Successfully!");
break;
}
else if(txtUsernameS.Text == arr.array[row,0])
{
MessageBox.Show("Username already Used.");
break;
}
}
}
}
if (row > 5)
{
MessageBox.Show("Sorry, maximum number of accounts has been reached.");
}
}
here's my code in frmProfile(form2)- In this form I just want the label to show the username of the user.
Tagasalo arr = new Tagasalo();
int row;
public frmProfile()
{
InitializeComponent();
}
private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
{
frmChangePassword changepass = new frmChangePassword();
changepass.Show();
this.Hide();
}
private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
{
frmMain logout = new frmMain();
logout.Show();
this.Hide();
}
public void frmProfile_Load(object sender, EventArgs e)
{
for (row = 0; row < 5; row++ )
{
if(arr.array[row,0] == arr.array[row,1])
{
lblUsername.Text = arr.array[row, 0];
break;
}
}
}
then, i want to change the password. replace the value of the array and when i log-out the array is empty again. I cant log-in again with the same account.
Tagasalo arr = new Tagasalo();
public frmChangePassword()
{
InitializeComponent();
}
private void btnSaveChanges_Click(object sender, EventArgs e)
{
if (txtCurrentPassword.Text == String.Empty)
{
errorProvider1.SetError(txtCurrentPassword, "Please type your Current Password.");
}
else
{
errorProvider1.Clear();
}
if (txtNewPassword.Text == String.Empty)
{
errorProvider2.SetError(txtNewPassword, "Please type your New Password.");
}
else
{
errorProvider2.Clear();
}
if (txtConfirmNewPassword.Text != txtNewPassword.Text)
{
errorProvider3.SetError(txtConfirmNewPassword, "Re-type your New Password.");
}
else
{
errorProvider3.Clear();
}
if(txtCurrentPassword.Text != String.Empty && txtNewPassword.Text != String.Empty && txtConfirmNewPassword.Text == txtNewPassword.Text)
{
MessageBox.Show("Changed Password Successfully!");
frmProfile profile = new frmProfile();
profile.Show();
this.Hide();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
frmProfile profile = new frmProfile();
profile.Show();
this.Hide();
}
Sorry if it's too long. I've been searching the net for days after school and I cant find the answer.