Click here to Skip to main content
11,496,146 members (807 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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 6:58am
Edited 2-Apr-12 7:04am
v2
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  
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 RyanDev 230
1 Sergey Alexandrovich Kryukov 114
2 Richard Deeming 100
3 OriginalGriff 89
4 Mostafa Asaduzzaman 59
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 3 Apr 2012
Copyright © CodeProject, 1999-2015
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