Strange code execution

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I am new to C#, that is why I am not sure what kind of problem it is: Is
VS files corrupted , or something else. that is the problems description:
I am working on a small database project. I am not using any data sources
Mysql, access etc. Instead I use binary formatter to store and read data. at
the beginning the program checks username/password. it does it in the
following way:

if(form2.initialized)
{
for(int i=0; i<database.users.Count;i++)
{
User user;
user=(User)database.users
s1=System.Text.ASCIIEncoding.ASCII.GetString (System.Convert.FromBase64String(user.username));
s2=System.Text.ASCIIEncoding.ASCII.GetString
(System.Convert.FromBase64String(user.password));
if(s1==form2.username.Text && s2==form2.password.Text)
{
accessmode=user.accessmode;
user.lastlogin=System.DateTime.Now;
SaveDatabase();
userlogged=true;
break;
}
}
}
if(!userlogged)
{
System.Windows.Forms.MessageBox.Show("Incorect
Username/Password.Access denied!");
Close(); //Code execution jumps here!!!
}

There is a strange problem: suppose user entered correct username/password,
that is, userogged=true, ok? surprisingly after break takes places code
execution jumps to Close() and form closes, even MessageBox.Show function
does not execute. The same occures in another code:

System.IO.Directory.CreateDirectory(df);
Form3 form3=new Form3();
form3.ShowDialog(this);
if(!form3.initialized)
{
System.Windows.Forms.MessageBox.Show("You must have at least one
administrator username and password. Try next time.");
Close();
}
execution jumps straight to Close() (not to MessageBox.Show(). if
form3.initialized==false, the program shows message box, in another case it
simply closes.
Can anyone clarify this point? May be VS files are corrupted, or there is an
error in code?
 
I'm not seeing a problem with your code.

1. I'd like to see the code that CALLS each of these.
2. You say that in the debugger, you are seeing the system jump to the
"close" call? Normally, I would look for things like misplaced commenting
causing a block to be balanced incorrectly, or a string that has been left
open. (One reason I don't particularly care for multi-line strings).
3. This is a good-old-fashioned stumper. If you think that some files are
corrupt, you can try creating a new project and copying the code files from
the old project. In fact, I usually consider it good practice to see if I
can extract a problem like this into a small snippet that exhibits the
behavior. That is something you can post or even share with product support
services. If you create a snippet like this, feel free to post it online.
That may help.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Default said:
Hi, I am new to C#, that is why I am not sure what kind of problem it is: Is
VS files corrupted , or something else. that is the problems description:
I am working on a small database project. I am not using any data sources
Mysql, access etc. Instead I use binary formatter to store and read data. at
the beginning the program checks username/password. it does it in the
following way:

if(form2.initialized)
{
for(int i=0; i<database.users.Count;i++)
{
User user;
user=(User)database.users;
s1=System.Text.ASCIIEncoding.ASCII.GetString (System.Convert.FromBase64String(user.username));
s2=System.Text.ASCIIEncoding.ASCII.GetString
(System.Convert.FromBase64String(user.password));
if(s1==form2.username.Text && s2==form2.password.Text)
{
accessmode=user.accessmode;
user.lastlogin=System.DateTime.Now;
SaveDatabase();
userlogged=true;
break;
}
}
}
if(!userlogged)
{
System.Windows.Forms.MessageBox.Show("Incorect
Username/Password.Access denied!");
Close(); //Code execution jumps here!!!
}

There is a strange problem: suppose user entered correct username/password,
that is, userogged=true, ok? surprisingly after break takes places code
execution jumps to Close() and form closes, even MessageBox.Show function
does not execute. The same occures in another code:

System.IO.Directory.CreateDirectory(df);
Form3 form3=new Form3();
form3.ShowDialog(this);
if(!form3.initialized)
{
System.Windows.Forms.MessageBox.Show("You must have at least one
administrator username and password. Try next time.");
Close();
}
execution jumps straight to Close() (not to MessageBox.Show(). if
form3.initialized==false, the program shows message box, in another case it
simply closes.
Can anyone clarify this point? May be VS files are corrupted, or there is an
error in code?
 
Back
Top