|
There is a commonly accepted statement that "goto is evil".
That my be a little extreme, but if it is to be used, it should be done with GREAT caution.
There are very few cases where goto is the best way to control program flow in modern day languages. Rewrite the code without using any goto(s) (and preferably with more descriptive variable naming) and it will be much easier to follow - and will most likely work!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Label_0104:
foreach (Character character in this.charSet)
{
foreach (CharClass class2 in classArray)
{
if (character.type == class2)
{
num17++;
goto Label_0104;
}
}
}
Stack overflows are often caused by an infinite loop in the code and that's what you have here.
When the condition character.type == class2 is true the outer loop restarts and then when the same condition is encountered for a second time, the loop restarts, and so on. I haven't read your code fully but I suspect that you meant to jump to a point after the end of the outer loop, not just before it's start.
Alan.
|
|
|
|
|
radhikasharma wrote: Label_0104:
foreach (Character character in this.charSet)///Error of stack overflow execption in Charset//
{
foreach (CharClass class2 in classArray)
{
if (character.type == class2)
{
num17++;
goto Label_0104;
}
}
}
What's that dude ????? Are you trying to live in danger ????? If I close my eyes to the ultimate sin (aka goto) the whole situation smells like an eternal loop.
|
|
|
|
|
Thanks for your response sir , please tell me the solution and wat iam doing wrong in the for each loop
please suggest me the right code so that i will not get any stack overflow exception error
also suggest any solution for the above error
with regards
radhika
|
|
|
|
|
Get rid of these goto statements. They produce the stack overflow. Goto is a relic in modern languages . Use a break statement as mentioned by many other people to exit the loop. Avoid by any means to use goto statements.
|
|
|
|
|
How do you keep a Aggie busy?
Write 'Please turn over' on both sides of a piece of paper.
|
|
|
|
|
Thanks alot sir ,my problem is solved
iam very much greatful to you
with regards
radhika
|
|
|
|
|
Where are the num12 , num14 , num20 , num22 and num24 variables?
Greetings - Jacek Gajek
|
|
|
|
|
My guess is someone elses DLL was disassembled.
|
|
|
|
|
It does look like the output from Reflector when used on a .net assembly, that was built in release mode, with the "Optimize code" box checked.
Maybe he should contact the person that wrote the original code to start with, and get the real, (hopefully commented) source. And hope that source isn't copyrighted....
|
|
|
|
|
Hi radhika!
Sorry it's a little late for this reply, but when I looked at your code I nearly cried.
I think your problem is solved, so some other suggestions:
* Invest some time in learning the basics of the environment and language you are using.
(I think you are new to programming) So you learn what type of errors can cause something
like StackOverflowException.
* Thinking about good variable names is never wasted time.
* Posts on any programming forum should never be in the style "I don't understand what you
are talking about - just give me the solution"
* If something compiles it doesn't mean that it is free of errors - NEVER! It just means
it's free of syntax-errors.
* If you have written such a long method - think about how to optimize: code length (maybe
split into several methods), readability (naming, comments, whitespace), functionality...
* Next time you want to use goto: leave it!
Another thing: Maybe you had some reason for all your Add(...Character(...)) lines but to me it looks very strange:
what about:
for(char ch = (char) 0; ch < 128; ch++)
{
}
|
|
|
|
|
Hello.. Sir
i am using a combobox and i am updating it from the database and also inserting value that is in the text of the combobox.its not working fine..
gives an error.........
Item collection cannot be modified when datasource property is set...
Thanks
|
|
|
|
|
when it is giving error? At the time of binding or at cother point.
post code where it gives the error
himanshu
|
|
|
|
|
|
i sent full article of this code to CODEPROJECT .
after that my article being accepted, you can use of them.
but code is like this:
you must use of NORTHWINFD Database
private void button1_Click(object sender, EventArgs e)
{
SqlConnection co = new SqlConnection();
co.ConnectionString = @"Server=.\SQLEXPRESS;initial catalog='NORTHWND.MDF';Trusted_Connection=Yes";
SqlCommand cmdSelect = new SqlCommand();
cmdSelect.Connection = co;
cmdSelect.CommandText = "SELECT (FirstName+' '+LastName) AS Fullname FROM Employees";
SqlDataAdapter da = new SqlDataAdapter(cmdSelect);
DataTable dt = new DataTable();
co.Open();
da.Fill(dt);
comboBox1.DataSource = null;
comboBox1.DataSource = dt;
comboBox1.ValueMember = "Fullname";
co.Close();
}
private void button2_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)comboBox1.DataSource;
DataRow dr = dt.NewRow();
dr[0] = "< select item >";
dt.Rows.InsertAt(dr, 0);
comboBox1.DataSource = dt;
comboBox1.SelectedIndex = 0;
}
|
|
|
|
|
Hi all
i am doing export to excel operation using below code.
public void ExcelExport(System.Data.DataTable tblExportData, string TempFilePath,string userInfo,bool headerStatus)
{
try
{
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Workbooks.Open(TempFilePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//Writing Header in Excel
if (headerStatus == true)
{
for (int i = 0; i < tblExportData.Columns.Count; i++)
{
excelApp.Cells[7, i + 1] = tblExportData.Columns[i].ColumnName;
}
}
//Writing Data in Excel
for (int i = 1; i <= tblExportData.Rows.Count; i++)
{
for (int j = 0; j < tblExportData.Columns.Count; j++)
{
string colName = tblExportData.Columns[j].ColumnName;
excelApp.Cells[i + 7, j+1] = tblExportData.Rows[i-1][colName];
}
}
//Create a worksheet object
Microsoft.Office.Interop.Excel.Sheets sheets = excelApp.Worksheets;
//from the collection of worksheet select one worksheet
Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
//select the cell in the worksheet
Microsoft.Office.Interop.Excel.Range myCell1 = (Microsoft.Office.Interop.Excel.Range)mySheet.get_Range("A6", "A6");
myCell1.Value2 = userInfo;
myCell1.Font.Color = System.Drawing.Color.Black.ToArgb();
excelApp.Visible = true;
}
catch (Exception ex)
{
}
}
it's working fine in local. but when i deployed this on server(e.g.relience server) then it stops to work. i mean exporting to excel not working. Even it's not generating any error and page is redirecting also. can any one help me please.
thanks to you all in advance.
Binod
|
|
|
|
|
Is excel installed on the server? Also improve your error handling, any errors generated are lost with your code.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I assume that this is being done in ASP.NET??
There's a few things you need to do to ensure that the application works. Note that the official MS line is that Excel is not a server component so they don't provide any support in that respect.
First things first - you'll need to have Excel installed on the server along with the interop assemblies.
Secondly, you need to ensure that the DCOM settings for Excel allow it to be launched from within IIS. You'll need to know what identity your web application will launch Excel as (it's usually NETWORK SERVICE, ASPNET or IUSR_<machinename> depending on your settings and version of IIS). To do this:
Start menu -> Run -> dcomcnfg.exe
Component Services -> Computers -> My Computer -> DCOM Config
Microsoft Excel Application -> Right Click, Properties -> Security Tab
From this tab you need to change the launch, access and configuration permissions to allow full and remote access to the user account you located above.
Next you'll need to do:
Properties -> Identity
select 'Interactive User'.
Finally you'll need to ensure that the webpage launching excel is correctly configured. The interop component expects to be run in a single thread apartment (STA) but ASP.NET defaults to multiple threads (MTA). You can force the use of an STA by including
AspCompat="true"
in the page directive header.
Finally you'll need to modify your web.config file to include a
identity impersonate="true"
section under system.web.
From the way you've written this code, I think you'll end up running into a problem that the instance of excel remains in memory after each export is performed. I don't have time to go into the detail but the problem is that you're not cleaning up objects once they've been disposed of. Note that when you create the export you're actually creating a number of objects (Application, Workbook, Worksheet, Range - at the very least) and all these need cleaning up.
There's articles out there on the web that will explain how to do this though it might take you a bit of trial and error.
Hope that helps!
It definitely isn't definatley
|
|
|
|
|
When one is writing an email in the "To:" textbox, gmail gives you choices of similar coincidences in a combobox-like way:
http://www.youtube.com/watch?v=bWy9SrhUpOM[^]
With the Combobox' AutoCompleteMode set to Suggest I can change the current text of the combobox, but how can I make it add the selection to the end of the current string?
modified on Wednesday, June 17, 2009 1:25 AM
|
|
|
|
|
Trun Yes on the AutocompleteMode and Autocomplete Source(SuggestAppend) properties
|
|
|
|
|
i gor error telling missing refference in PixelData...
may i know what refferance...?
i'm tring to do QR barcode decoder...
private void button2_Click(object sender, EventArgs e)
{
unsafe
{
Image image = Image.FromFile("D:\\1.JPG");
BitmapData bd = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
int sourceWidth = image.Width * System.Runtime.InteropServices.Marshal.SizeOf(typeof(PixelData));
if (sourceWidth % 4 != 0)
sourceWidth += (4 - (sourceWidth % 4));
Byte* bitmapBaseByte;
bitmapBaseByte = (Byte*)bd.Scan0.ToPointer();
PixelData* pPixel;
for (int y = 0; y < height; y++)
{
pPixel = (PixelData*)(bitmapBaseByte + y * sourceWidth);
for (int x = 0; x < width; x++)
{
intImage[x][y] = (int)((0xff << 0x18) | (pPixel->red << 0x10) | (pPixel->green << 8) | pPixel->blue);
pPixel++;
}
}
image.UnlockBits(bd);
}
anyone just help me....thanks...
A S E L A
modified on Wednesday, June 17, 2009 2:10 AM
|
|
|
|
|
Is there any way to know which the PDF is currently opened. If there are many instances of Acrobat Reader are obtained, then also, I have to get all the PDF documents opened.
How can I do this?
Don't Say that "You can't do", I think there will be definitely something to do this.
any suggestion can be posted here.
Thank You...
|
|
|
|
|
I want to put this line of numbers:
9 1 10 10 8 2 7 2 9 0 10 9 1 8 2 10 7 2 -1
into a 19 number array array[19]
I am reading those numbers from a text file, but I don't know how to assign them to an array?
This is what I have so far, its reading from the text file....
<br />
int main(void)<br />
{<br />
<br />
char ch;<br />
char string [256];<br />
int i;<br />
int raw;<br />
FILE *fin, *fout;<br />
fin=fopen("g:/cfinal/bowlin.txt", "r");<br />
fout=fopen("g:/cfinal/bowlout.txt", "w");
|
|
|
|
|
You have the wrong forum, this forum is for C#
only two letters away from being an asset
|
|
|
|
|
Hello all
I have a mysql table with some rows in it that contain a path to a jpg file.
Here is a example of the path:
images/portfolio/lille_ilveaWebshop.jpg
The file excists on the webhost so that is not a problem.
I am loading the jpg file into a bitmap in a foreach.
It works fine when I am on a local server, but when I upload it to my webhost it says:
<quote>Server Error in '/' Application.
Out of memory.
Exception Details: System.OutOfMemoryException: Out of memory.
[OutOfMemoryException: Out of memory.]
System.Drawing.Bitmap..ctor(String filename) +376480
Referencer.Page_Load(Object sender, EventArgs e) +561
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627</quote>
I cant seem to figure out just why it would do that.
Here is the code I am using:
foreach (
DataRow Row in objPortFac.VisReference(refKatID).Rows)
{
// Create a new bitmap with the path from the row
// fldStortBillede is the field that contains the path
Bitmap objStortBillede = new Bitmap(Server.MapPath(Row["fldStortBillede"].ToString()));
// Dispose the bitmap after use
objStortBillede.Dispose();
}
Any suggestions?
|
|
|
|