|
These two programs are giving errors while compiling.
WAP that counts the no. of occurence of particular character in a line of text.
class demo
{
private int Occurance(string Input, string Find)
{
System.Text.RegularExpressions.Regex rx =
new System.Text.RegularExpressions.Regex(Find);
// to display them do this
System.Text.RegularExpressions.Match mt = rx.Match(Input);
while (mt.Success)
{
System.Console.WriteLine("Found >>" + Find + "<< at position " + mt.Index.ToString());
mt = mt.NextMatch();
}
// end display
return rx.Matches(Input).Count;
}
}
This program is giving error that entry point is not defined.
-------------------------------
WAP to take 2 dates using objects(day,month,year)& display both dates,their comparison also that which one is greater(take the dates with the help of three parameter constructors)
class demo
{
private DateTime getDate(int day, int month, int year)
{
return new DateTime(year, month, day);
}
private void compareDates(DateTime a, DateTime b)
{
if (a > b)
Console.WriteLine(a.ToShortDateString() + " > " + b.ToShortDateString());
else if (a == b)
Console.WriteLine(a.ToShortDateString() + " = " + b.ToShortDateString());
else
Console.WriteLine(a.ToShortDateString() + " < " + b.ToShortDateString());
}
}
this program is giving error "type or namespace couldnot be found(are u missing a using directive or an assembly reference).
|
|
|
|
|
1. You haven't defined an entry point. Where's your Main()?
2. Are you creating a dll?
BTW: Make your title more descriptive in the future.
|
|
|
|
|
Remember that the sintax is:
using System;<br />
<br />
namespace demo<br />
{<br />
public class demo<br />
{<br />
public demo()<br />
{<br />
}<br />
<br />
public Main()<br />
{<br />
this.demo();<br />
}<br />
<br />
private int Occurance(string Input, string Find) <br />
{ <br />
System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(Find);
System.Text.RegularExpressions.Match mt = rx.Match(Input); <br />
while (mt.Success) <br />
{ <br />
System.Console.WriteLine("Found >>" + Find + "<< at position " + mt.Index.ToString()); <br />
mt = mt.NextMatch(); <br />
}<br />
<br />
return rx.Matches(Input).Count; <br />
} <br />
<br />
private DateTime getDate(int day, int month, int year) <br />
{ <br />
return new DateTime(year, month, day); <br />
} <br />
<br />
private void compareDates(DateTime a, DateTime b) <br />
{ <br />
if (a > b) <br />
{<br />
Console.WriteLine(a.ToShortDateString() + " > " + b.ToShortDateString()); <br />
}<br />
else if (a == b) <br />
{<br />
Console.WriteLine(a.ToShortDateString() + " = " + b.ToShortDateString()); <br />
}<br />
else <br />
{<br />
Console.WriteLine(a.ToShortDateString() + " < " + b.ToShortDateString()); <br />
}<br />
} <br />
<br />
~demo()<br />
{<br />
}<br />
<br />
}<br />
}
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
I hope I'm just missing something basic.
Is it possible to have a custom background (say, gradient) for a System.Windows.Forms.Button without having to do *ALL* the drawing yourself.
OnPaintBackground does not appear to be called; the paint code for Button appears to be integrated with it's background logic.
|
|
|
|
|
I think you should be able to do this without much problem by creating a csutom control which derives from Button class.
You can override the OnPaint method and call base.OnPaint() so that it would do all the normal painting required for creating a Button and the you could draw whatever you want, like gradient or ...
---
"Drawing on my superior command of language I said nothing."
|
|
|
|
|
That solution will not let you paint the background and ignore the foreground. The need is to have a custom background, but let .NET draw the foreground image and text. The calculations of *where* the image and text appear is fairly convoluted due to the ImageAlign, TextAlign, and TextImageRelation properties.
I have pretty much confirmed this is not possible as .NET draws the button background and image/text in one operation, giving derived classes no opportunity to inject in the process.
Thank you for the answer.
|
|
|
|
|
Can't you set a picture as the background of a button? and have another picture for the foreground, and text and all that other stuff?
Or is it I that is confused?
|
|
|
|
|
Hello,
I'm using an Access file as a data source but am having problems when it comes to saving to the "database." If I do not "copy the file into the project" it works fine but if I copy it into the project it won't save. I need to get it into the project.
Also, for this project I'm having a little bit of a problem with the SELECT query:
I'm taking a C# entry level course and the book we're using gives this example:
SELECT Bla, BLa, Bla.... FROM dbo.Addresses WHERE LastName = @lastName
I'm trying to do a query exactly like this but it gives me an error:
Error in WHERE clause near '@'. Unable to parse query text.
Using this query:
SELECT PartNumber, PartName, Description, Price, Quantity FROM Invoices WHERE PartNumber = @partNumber
If I ignore the error, the @partNumber parameter doesn't show up in the Adapter window.
Thanks
|
|
|
|
|
I don't understand what you are try to do with the Access file. However, on the web server, you must give ASPNET write accesss in order for ASPNET to INSERT or UPDATE the Accesss file.
The data provider for Access does not support named parameters such as "@lastName". You have to use unnamed parameters using "?":
SELECT * FROM Addresses WHERE LastName = ?
|
|
|
|
|
Is it possible to edit the properties for a file such as the ones that can me found on the summary tab. i.e. author, title, comments, keywords, etc...
thanks.
|
|
|
|
|
Ok, I was just debugging my little web browser app I was creating and before Form1 even loads, I get the litte yellow highlight over this text:
Application.Run(new Form1());
With this message:
"Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead."
This is in Program.cs, I am new to C# and so do not really understand what the error is, I haven't changed anything in Program.cs atall, just the regular Form.cs
Can somebody please tell me what the hell it is trying to tell me?
Thanks,
Any reply is appreciated.
|
|
|
|
|
Is your Form1 attempting to show another form somewhere using Application.Run() ??
|
|
|
|
|
Not atall, Form1 just contains a textbox and a menustrip so far with a File>New that creates a new instance of a class called File in Text.cs
|
|
|
|
|
Hi,
In my C# Win form (.NET 2.0 - VS 2005), I have 4 datagridviews which are filled by 5 different data tables.
these data tables are directly filled by 5 different SQL Server Everywhere Tables.
Now, Placed all Table Saving Codes within a single method event handler for the save button.
Like this,
private void saveAll()<br />
{<br />
this.Validate();<br />
this.myBindingSource1.EndEdit();<br />
this.myDataSet.MytableAdapter1.Update(.....);<br />
<br />
this.validate();<br />
this.myBindingSource2.EndEdit();<br />
this.myDataSet.MytableAdapter2.Update(.....);<br />
<br />
this.validate();<br />
this.myBindingSource3.EndEdit();<br />
this.myDataSet.MytableAdapter3.Update(.....);<br />
}
Now, When I call the save method, most of the time, I get Error with the message "Concurrency Violation."
Is there any way I can get rid of this problem ?
Thanks in advance,
Emran
|
|
|
|
|
Are any constraints on database children?
|
|
|
|
|
Hi,
Thanks for your reply.
No, My tables are independent, they are not related to any other table as Parent Child and thus there is no question of constraint. Is there any other possibilities for getting rid of this error ?
Regards
Emran
|
|
|
|
|
Your problem is more than likely related to your update commands or identity column
|
|
|
|
|
Thanks for your reply. Right, I have identity column in my tables. But I was wondering the concurrency conflict doesn't occur all the time, but most of the time. I am not sure what to fix in my query or code to get rid of it.
Regards
|
|
|
|
|
how to save a file in c#
Don't wait to hear a word of thanks from anybody when you help them instead ask them to help three other people and ask them to continue in chain.
|
|
|
|
|
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "Text Files|*.txt|Comma Seperated Files|*.csv|All Files|*.*";
dlg.InitialDirectory = @"C:\";
if (dlg.ShowDialog() == DialogResult.OK)
{
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(dlg.FileName))
{
writer.Write(txtContent.Text);
writer.Flush();
}
}
The Filter property is a pipe (vertical bar) separated list of file type descriptions and file type filters that must be paired. So in the above example, when the Save File Dialog is shown, the 'File Types' drop down will contain 3 entries: one for Text Files, which will expect a .txt extension, one for Comma Seperated Values, which will expect a .csv extension, and one for All Files, which will take any extension. The OpenFileDialog class works in the same way.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
Thanks, this has really helped me, codeproject is awesome
|
|
|
|
|
No problem. And yes it is!
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
How do you learn stuff like that, have you got books? If so, can you recommend any good ones?
Thanks.
|
|
|
|
|
Part of it is from books, part of it is from shear experience in the work force. I've been writing software, both Windows and Web for quite a while now, and these are just the sort of things you tend to pick up. Your best bet for learning the framework stuff is to pick an applicaiton, and make your own version of it, simply for the learning experience of how to do it. A notepad clone, with a multi-document interface, toolbars, a status bar, menus, context menus, file opening and saving, and any other features you can think of. Start with small pieces, and work your way up.
You can also jump over to Amazon.com and do a search for Beginning C#. There's a ton of books available, some better than others, so make sure to read the buyer comments before making a purchase.
Also, this site here truly is a wonderful resource, and if you're new to it, you should become as familiar with it as possible. If you can't find what you're looking for in an article, then by all means, post a question in the forum. Just make sure it's the correct forum if you don't want to get flamed. Folks here may not always have the correct answer, but chances are that someone can atleast point you in the right direction.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
Lol ok, thanks mate. A text editor is actually what I am trying to create. Somewhere else in the forum a guy said he needed to make a text editor for a project at a training place or something, so I wanted to see if I was up to it. Thanks for the Save part of it, I'll just try and work out the Open and other stuff part.
Im sure it will be pretty similar.
Thanks.
|
|
|
|
|