Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I'm developing c# app, and one I choose form this message comes out

value doesn't fall within the expected range
instances of this error
show call stack
Posted
Comments
[no name] 8-Dec-12 2:56am    
could you please add your code ??
Member 8584763 8-Dec-12 3:02am    
<pre lang="c#">
namespace pharmcy
{
public partial class MDIParent3 : Form
{
// private int childFormNumber = 0;
SqlConnection con=new SqlConnection ();
SqlCommand cmd=new SqlCommand ();
int i=1;

string a = "l.bak";
string x = @"c:\SQLBackup\";

public MDIParent3()
{
InitializeComponent();
}

private void ShowNewForm(object sender, EventArgs e)
{
Sale s = new Sale();
s.MdiParent = this;
s.Show();
}

private void OpenFile(object sender, EventArgs e)
{
deleteproduct s = new deleteproduct();
s.MdiParent = this;
s.Show();
}

private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
saveFileDialog.Filter = "Text Files (*.bak)|*.bak|All Files (*.*)|*.*";
if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = saveFileDialog.FileName;
}
}

private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}

private void CutToolStripMenuItem_Click(object sender, EventArgs e)
{
}

private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
{
}

private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
{

}

private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}

private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}

private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}

private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.ArrangeIcons);
}

private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childForm in MdiChildren)
{
childForm.Close();
}
}

private void backupToolStripMenuItem_Click(object sender, EventArgs e)
{
backup b = new backup();
b.ShowDialog();
}


public void backup()
{
string iii=".bak";
string xxx = dateTimePicker4.Text;
string y = Convert.ToString(i);
string format = ("yyyy-MM-dd");
DateTime f = Convert.ToDateTime(xxx);
string yy = f.ToString(format);
bool ii = true;
int number = 1;
x += yy;
x += iii;
bool bBackUpStatus = true;
Cursor.Current = Cursors.WaitCursor;
try
{
con.Open();
if (Directory.Exists(@"c:\SQLBackup"))
{
while (ii)
{
if (!File.Exists(x))
{
ii = false;
bBackUpStatus = true;
break;
}
else
{
y = (number + 1).ToString();
x += y;
bBackUpStatus = false;
}
}
/*if (File.Exists(@"c:\SQLBackup\wcBackUp1.bak"))
{
if (MessageBox.Show(@"Do you want to replace it?", "Back

1 solution

I assume the error is happening here somewhere:
C#
string iii=".bak";
string xxx = dateTimePicker4.Text;
string y = Convert.ToString(i);
string format = ("yyyy-MM-dd");
DateTime f = Convert.ToDateTime(xxx);
string yy = f.ToString(format);

For starters, don't use DateTimePicker.Text - it has a Value property which returns a DateTime directly, so you do not need to do any conversion.
You don't use the value in "y", so ythere is no need to assign it.
You don't need brackets round a string literal
C#
string iii=".bak";
string y;
string format = "yyyy-MM-dd";
DateTime f = dateTimePicker4.Value;
string yy = f.ToString(format);

In fact, I would simplify this a bit:
C#
string iii=".bak";
string y;
string yy = dateTimePicker4.Value.ToString("yyyy-MM-dd");
And I would change the names as well:
C#
string backupExt = ".bak";
string temp;
string dateFormatted = dateTimePicker4.Value.ToString("yyyy-MM-dd");
 
Share this answer
 
Comments
Member 8584763 8-Dec-12 3:28am    
Still the same problem? What do you think?
OriginalGriff 8-Dec-12 4:16am    
Exactly which line is reporting the problem? What are the relevant variable contents?
Member 8584763 8-Dec-12 4:24am    
the warning is value doesn't fall within the expected range line 0?
OriginalGriff 8-Dec-12 4:27am    
:laugh:
No - which line of code? The debugger will stop at a particular line in your source code when it reports the problem. Which line is it?
Member 8584763 8-Dec-12 4:41am    
No,the code works fine ,but when I open the design it gives this message
value doesn't fall within the expected range

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900