Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI C# WPF
Hi All,
 
I am getting following assertion on using the below statement in WPF Application,
 
"ArgumentOutOfRangeException was unhandled by user code"
 
In my Print.Xaml.cs
 
I have TextBox and need to pass the same to managed code(C++/CLI) from C#(.Net)
 
private UInt32 _ValueCntTextBox = 0;
//.....

private void UpdatePrintInfo()
{
 
line 1: int value = PrintInfoTextBlk.Text.IndexOf(':');
line 2: string mystring = PrintInfoTextBlk.Text.Substring(value +1,PrintInfoTextBlk.Text.IndexOf(')' )-value -1);
line 3: ValueCntTextBox.Text = value;
line 4: UInt32.Parse(value,out _ValueCntTextBox);
 
...
...
}
The above Exception is obtained @ line 2:
Any Help in resolving the above is much appreciable.
 
I am using Windows 7 O/S, VS2008 IDE
With Regards,
Samanth_90
Posted 2-Apr-12 5:58am
Edited 2-Apr-12 6:04am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What is the value of the parameters in the PrintInfoTextBlk.Text.Substring() call? For example what does value contain, and what does PrintInfoTextBlk.Text.IndexOf(')' ) return?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

From the code above, I suppose you are trying to extract the text portion between ':' and ')'.
 
I would code like:
// save text to avoid accessing underlying control multiple times
string sText = PrintInfoTextBlk.Text;
// save position of ':' if present; -1 otherwise!
int nStartIndex = sText.IndexOf(':');
// save position of ')' if present; -1 otherwise!
int nEndIndex = sText.IndexOf(')');
 
string mystring = null; // null will later tell that no valid chars have been found
					
// Both chars were found, so extract substring
if ((nStartIndex >= 0) && (nEndIndex > nStartIndex))
    mystring = sText.Substring(nStartIndex + 1, nEndIndex - nStartIndex - 1);
// Only ':' was found, so extract everything until end of text
else if ((nStartIndex >= 0) && (nEndIndex < 0))
    mystring = sText.Substring(nStartIndex + 1);
 
ValueCntTextBox.Text = nStartIndex;
UInt32.Parse(nStartIndex, out _ValueCntTextBox);
  Permalink  

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 598
1 OriginalGriff 235
2 George Jonsson 230
3 CPallini 210
4 PIEBALDconsult 150
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,263
2 CPallini 4,750
3 George Jonsson 3,227
4 Gihan Liyanage 2,487


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 3 Apr 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