Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 7-Dec-12 21:53pm
Comments
Krunal Rohit at 8-Dec-12 2:56am
   
could you please add your code ??
Member 8584763 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I assume the error is happening here somewhere:
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
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:
string iii=".bak";
string y;
string yy = dateTimePicker4.Value.ToString("yyyy-MM-dd");
And I would change the names as well:
string backupExt = ".bak";
string temp;
string dateFormatted = dateTimePicker4.Value.ToString("yyyy-MM-dd");
  Permalink  
Comments
Member 8584763 at 8-Dec-12 3:28am
   
Still the same problem? What do you think?
OriginalGriff at 8-Dec-12 4:16am
   
Exactly which line is reporting the problem? What are the relevant variable contents?
Member 8584763 at 8-Dec-12 4:24am
   
the warning is value doesn't fall within the expected range line 0?
OriginalGriff at 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 at 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
OriginalGriff at 8-Dec-12 4:52am
   
The Design? Odd. Does it give any further details?
Member 8584763 at 8-Dec-12 4:56am
   
there are the warnings:
Warning 1 Value does not fall within the expected range.
Warning 4 ResX file Value does not fall within the expected range. Line 128, position 5. cannot be parsed. 128 0
Warning 5 Could not determine the dependencies of the COM reference "CRQUERYENGINE". Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)) pharmcy

OriginalGriff at 8-Dec-12 5:05am
   
I suspect the first two are the same error - so have a look at the line it complains about.
In VS, open the relevant code file, and press CTRL+G. Enter "128" and press OK - that should tell us which line it does not like.
Member 8584763 at 8-Dec-12 5:20am
   
what's the relevant code file? where to find it
OriginalGriff at 8-Dec-12 5:28am
   
Normally the error message tells you that!
OriginalGriff at 8-Dec-12 5:29am
   
Try double clicking the error message - with any luck it will take you to the offending line.
Member 8584763 at 8-Dec-12 5:34am
   
Even I double click on it .It doesn't show anything?

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 230
2 DamithSL 220
3 Zoltán Zörgő 150
4 Maciej Los 135
0 OriginalGriff 7,740
1 DamithSL 5,694
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,061
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100