|
I recommend to leran how to use the debug functions in the IDE. It is very useful that you can step through the code and discuver all errors and the actual behaviour of the application
|
|
|
|
|
I am getting a strange problem when I try to run a program for my C# class.
I need to input 10 numbers each into two arrays. Then I need to extract each of the numbers and their corresponding numbers in the second array. These two get added together and stored into the third array.
I can get my numbers into the two arrays. When I press Enter, I end up getting a message that there was an exception and it wants to e-mail it to Microsoft. Below is my code for displaying the results. At one time I could at least, get it to do a Console Write Line.
Can anyone see where I’m making my mistake? I am only looking to find out why it is giving me the error message, and trying to send it to Microsoft. Any help would be appreciated.
public static void DisplayNumbers(double anArray1, double anArray2, double anArray3)<br />
{<br />
string results = " "; <br />
int counter = 0;<br />
<br />
for (int x = 0; x < anArray3; x++)<br />
{<br />
anArray3 = anArray1 + anArray2;<br />
Console.WriteLine();<br />
Console.WriteLine("{0}\t" + "+" + "\t{1}\t" + "=" + "\t{2}", anArray1, anArray2, anArray3);<br />
while (counter < 10)<br />
{<br />
counter++;<br />
results += "{0}\t" + " + " + "\t{1}\t" + " = " + "\t{2}" + anArray1 + anArray2 + anArray3;<br />
}<br />
string caption = "Array Methods Illustrated";<br />
string outputMsg = "Array Numbers Shown\n\n" + "First\t" + "Second\t" + " " + " Sum\n";<br />
MessageBox.Show(outputMsg, caption);<br />
}
I'm listing the error I'm recieving and I'm also showing what is on Line 18.
"Unhandled Exception: System.IndexOutOfRangeException: Index was outside the
bounds of the array at Exer4Chpt7.Program.main<> in G:\Programs\Exer4Chpt7\
Exer4Chpt7\program.cs: Line 18"
Line 18: double[] anArray1 = new double[10];
Thanks again.
|
|
|
|
|
Hi
Y don't you change this line of code for (int x = 0; x < anArray3; x++)
to for (int x = 0; x < 10; x++) and see.
Sri
|
|
|
|
|
Hi All,
I have the application developed in MS Dos Basic 3.0.
I want to convert or reverse engineering that application into .Net 2005 C#.
Kindly provide suggestion or ways (any kind of parser is available).
thanks in advance.
Mack
|
|
|
|
|
Asked and answered in the VB.NET Forum. Please don't cross post in multiple forums.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
yes Dave i will take care of such things.
|
|
|
|
|
Hi,
We are currently building a Windows Application with Visual Studio, C# and SQL. Exceptions are caught and logged.
Is there a way for us to determine the exact spot in the code where the error occurred, that is the CLASS and the METHOD?
Here is the code we use now:
catch (Exception error)<br />
{<br />
ExceptionHandler.LogError(error, Applications.ID, UserProfile.UserID, Applications.Version);<br />
throw error;<br />
}
The error object gives us Source and StackTrace, but not location.
Thanks for any help,
Anne
|
|
|
|
|
AnneThorne wrote: catch (Exception error)
{
ExceptionHandler.LogError(error, Applications.ID, UserProfile.UserID, Applications.Version);
throw error;
}
I would probably suggest changing your function to take two more parameters 'this'(which would give you the name of the class sending you error) and a string to have the method name.
ExceptionHandler.LogError(error, Applications.ID, UserProfile.UserID, Applications.Version,this,"this method">");
you can actually use the StackFrame class in "System.Diagnostics;" to get the information you want.
you can change your function to take 2 more parameters
ExceptionHandler.LogError(error, Applications.ID, UserProfile.UserID, Applications.Version, this, new StackFrame().GetMethod().Name);
Last modified: 9mins after originally posted --
|
|
|
|
|
That appears to give the name of the method that's calling LogError, but the exception may have occured deeper and been bubbled up until finally caught.
This is something that I'm trying to work out as well.
|
|
|
|
|
Try
new System.Diagnostics.StackTrace ( error ).GetFrames()[0].GetMethod().Name
the only shortcoming is that it requires debug info to do what I want.
Generally release builds don't include debug info.
I'm still trying to figure the proper settings for a VS project.
When I compile on the command line (with CSC) the switch is /debug+ .
|
|
|
|
|
namespace Template
{
public partial class Template
{
private static int
div
(
int lhs
,
int rhs
)
{
return ( lhs / rhs ) ;
}
[System.STAThread]
public static int
Main
(
string[] args
)
{
int result = 0 ;
try
{
int x = int.Parse ( args [ 0 ] ) ;
int y = int.Parse ( args [ 1 ] ) ;
int z = div ( x , y ) ;
}
catch ( System.Exception err )
{
while ( err != null )
{
string sep = " ( " ;
System.Reflection.MethodBase meth =
new System.Diagnostics.StackTrace ( err ).GetFrames()[0].GetMethod() ;
System.Console.Write ( meth.DeclaringType.FullName + "." + meth.Name ) ;
foreach ( System.Reflection.ParameterInfo parm in meth.GetParameters() )
{
System.Console.Write ( sep ) ;
if ( parm.IsOut )
{
System.Console.Write ( "out" ) ;
}
System.Console.Write ( parm.Name + " " + parm.ParameterType.Name ) ;
sep = " , " ;
}
System.Console.WriteLine ( " ) " + err.Message ) ;
err = err.InnerException ;
}
}
return ( result ) ;
}
}
}
C:\>err
Template.Template.Main ( args String[] ) Index was outside the bounds of the array.
C:\>err jkfg
System.Number.StringToNumber ( str String , options NumberStyles , number NumberBuffer& , info NumberFormatInfo , parseDecimal Boolean ) Input string was not in a correct format.
C:\>err 1 jkfg
System.Number.StringToNumber ( str String , options NumberStyles , number NumberBuffer& , info NumberFormatInfo , parseDecimal Boolean ) Input string was not in a correct format.
C:\>err 1
Template.Template.Main ( args String[] ) Index was outside the bounds of the array.
C:\>err 1 jkfg
System.Number.StringToNumber ( str String , options NumberStyles , number NumberBuffer& , info NumberFormatInfo , parseDecimal Boolean ) Input string was not in a correct format.
C:\>err 1 5
C:\>err 1 0
Template.Template.div ( lhs Int32 , rhs Int32 ) Attempted to divide by zero.
C:\>err 1 0.0
System.Number.StringToNumber ( str String , options NumberStyles , number NumberBuffer& , info NumberFormatInfo , parseDecimal Boolean ) Input string was not in a correct format.
|
|
|
|
|
I was at a training session yesterday and noticed the developers has placed a small red triangle in the top left corner of a text box to indicate the field was a mandatory field. I thought this would be nice to do in my apps.
Does anyone know where I could learn procedure on how to make a custom control like this.
Regards
Jeff
|
|
|
|
|
You may read about custom controls at the MSDN.
|
|
|
|
|
Hi guys,
How can I get the resources from a dll, the dll contains a resource(myresource.resx) file.
Can you guys please demonstrate some examples.
Thanks
|
|
|
|
|
I tend to write a dll that has methods that know how to return objects from it's resources.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I am using VS.Net 2005
the DataGridView i use it has a ComboBox column
(Disply Member is Product Name but Value Member is Product ID)
i have a nother column for BarCode i want when i insert the BarCode Number in this column the value member of the combobox chenge and disply the product name of this value
this is the code i wrote but it doesn't work
private void GV_OrderDetails_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (GV_OrderDetails.CurrentCell.ColumnIndex == 6)
{
string BarCodeText = GV_OrderDetails.CurrentCell.Value.ToString();
if (BarCodeText.Length > 4)
{
DV_Pro.RowFilter = "Pro_ID='" + BarCodeText.Substring(0, 4) + "'";
GV_OrderDetails[2, GV_OrderDetails.CurrentRow.Index].Value = BarCodeText.Substring(0, 4);
}
}
}
catch
{ }
}
MD_NADA
|
|
|
|
|
Hi Guys,
I've been looking around for a while now, i've seen lots of classes in the .net framework that use sections of xml in the app / web.config to setup the class. I'm sure it's possible to create my own, and I'm wondering if someone can point me in the right direction for some resources on the subject.
Cheers
Tris
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
|
Excellent -
Thanks Pete.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
i am working on a project to communicate with clinets using tcp/ip protocol.
I have a server system where this program is being done. I have clinets which are connnected to my ip. These clients are capable of accepting commands from the server and gove reply for that. For eg:- if i give %Name to clinet it will send back the system ip address.
private void button1_Click(object sender, EventArgs e)
{
Listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any,5005);
Listener.Bind(ipLocal);
Listener.BeginAccept(new AsyncCallback(OnClientConnect), null);
}
private void OnClientConnect(IAsyncResult asyn)
{
Client = Listener.EndAccept(asyn);
WaitForData();
}
private void WaitForData()
{
Client.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), null);
}
private void OnDataReceived(IAsyncResult asyn)
{
Byte[] sendBytes = Encoding.UTF8.GetBytes("%Name");
string szData;
int iRx = 0 ;
iRx = Client.EndReceive(asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
szData = new string(chars);
MessageBox.Show(szData.ToString());
Client.Send(sendBytes);
WaitForData();
}
The sending of data is working fine here. but when i revceive data they are all junk values even after converting to string. Junk vlaues means some single characters only
Please let me know if tehre is someone extertise in this feild as i am new to this
Thanks in advance
Harikrishnan
|
|
|
|
|
I've used:
string receivedText = System.Text.Encoding.ASCII.GetString(buffer, 0, buffer.Count));
Of course this assumes that "buffer" in your case is a byte array.
Also, please be sure to check what the client is supposed to be sending. Is it an array of values that need interpreting? Or is it a human readable string?
Phil
|
|
|
|
|
Hi
I have added a checkbox to my gridview using a template field with autopostback for the checkbox , but I can't find a way to to retrieve gridview data for the row checked.
Can anyone help please ?
thanks:
confused:
|
|
|
|
|
Hi all,
i've developed screens using Microsoft InforPath, and now i wanna add all the forms to my windows application in VISUAL STUDIO 2005,
Do we need to add any plug-in to do this?
can u please suggest me the solution.
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
I want to take very fast screenshots of my full screen with a timer. I hope this can be done with DirectX.
On this page[^] is an example of doing this in C++. But... the rest of my project is in C#, so I hope it also can be done in C#. I need the screenshot as a Bitmap variabele, it won't be saved as a file.
Hopefully, someone got a full sourcecode example, because I don't know much of DirectX.
|
|
|
|
|
A generic collection i.e. cCurves is populated with data.
The collection has several fields.
I am interested in two of the fields i.e. Name and Name2
As a test, the following return data from the collection.
cCurves[0].Name1
cCurves[0].Name2
cCurves[1].Name
cCurves[1].Name2
cCurves[2].Name
cCurves[2].Name2
...
How can I use a loop to populate a simple array with the
data (Name, Name1 fields for each row) in the above collection please?
Thanks
|
|
|
|