 |

|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|

|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|

|
hi,
is there a way that i can get the attributes in my class dynamically like calling a function which return all the attributes in my class in an list/array?
however, without hard-coding so that even when my class attributes changes i dont need to change this function
|
|
|
|

|
Try:
Type type = typeof(MyClass);
object[] oat = type.GetCustomAttributes(true);
foreach (object at in oat)
{
Console.WriteLine("{0}", at.ToString());
}
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|

|
The method 'PrintAuthorInfo in this on-line MSDN example of custom Attribute use [^] shows you how to get all the Attributes into an Array of System.Attribute, and access fields, and call a function that returns a string.
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|

|
Hi,
Please let me know how may I store follow string value into string variable ?
string myValue = "aa[a"a]aa";
Thank you in advance
|
|
|
|

|
use a backslash to escape the quote
string myValue = "aa[a\"a]aa";
|
|
|
|

|
string d = "this is a open quote \" and this is a \" close Quote";
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|

|
To add to what Davey and Simon have said, '\' is an "escape" character, which tells the compiler that the following character is a special, rather than a standard character. A '\' followed by double quote is a double quote character rather than the end of the string, and other sequences have different meaning, such as \\ for a '\' character, \n for a newline and \t for a tab. You can also use:
string myValue = @"aa[a""a]aa"; The '@' turns off recognition of the '\' as a special, allowing you to type a single '\' character if you are entering a path:
string mypath = "D:\\Temp\\myfile.txt";
Or
string mypath = @"D:\Temp\myfile.txt"; When you use a '@' prefix, you use tqo double quote characters together to insert a single double quote character in the string.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|

|
hi
does anyone know how i can create a general log eg if i had classes
student: id,name,age
and
teacher: id, name, nation
as you can see the 2 class differs
is it possible to create a table which can save each changes i make like a log?
so that i can see the changes i made.
|
|
|
|

|
Where do you want to save the information and in what format? If you just want general logging of transactions then take a look at log4net Tutorial[^].
Use the best guess
|
|
|
|
|

|
neodeaths wrote: is it possible to create a table which can save each changes i make like a log?
Do you mean an audit log?
If so, are you saving these objects to database already?
If the answer to both these is yes, then you can use database triggers (depending on your database) for each of the CRUD operations. If not, can you let me know what you are trying to achieve.
“Education is not the piling on of learning, information, data, facts, skills, or abilities - that's training or instruction - but is rather making visible what is hidden as a seed” “One of the greatest problems of our time is that many are schooled but few are educated”
Sir Thomas More (1478 – 1535)
|
|
|
|

|
As Richard M. suggests, you need to define what you are logging, what format it's in.
Is the logfile you want to create a time-stamped transcription of events as they happen, like the one log4Net creates ?
Or, is it possible that you actually want to have a persistent set of the "states" of each variable over time in memory ? If so, that means a data-structure ... perhaps a LIFO or FIFO stack ... and controlling the "depth" of how many states are stored.
Do you want to use a robust ready-to-go solution, like log4Net, or do you want to build-your-own limited logging facility ? Do you want to log errors/exceptions ?
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|

|
hi,
i mean i would like to log successful edits to objects in my application.
does log4net facilitate this?
|
|
|
|

|
neodeaths wrote: is it possible to create a table which can save each changes i make like a log?
You need to differentiate between trace logging and business logging.
Trace logging is output that helps a developer figure out why a production system fails. It exists to solve problems that are unexpected.
Business logging is used by users to figure out what happened, perhaps problems or just validation. It exists to solve problems that are known, for the most part.
The first uses a log library and log files because database failures are something that needs to be trace logged.
The second needs a more formal persistence solution such as a database table
The second probably needs a custom solution depending on business requirements.
The first can use existing libraries. My perception is than log4net is not an ideal solution. The nlog library provides a better solution although even that is not ideal.
|
|
|
|

|
Hello forum,
(sorry if duplicate, I might have post this but cannot find it)
Just created a SL Busines application. In the MYDomainService.cs the default queries are generated.
public IQueryable GetDBTablesCompare()
{
return this.ObjectContext.DBTables;
}
The default returns all columns in the specified table.
I would like to run a script like this:
SELECT * From DBTables A
FULL OUTER JOIN Information_Schema.Columns B ON A.Column_Name = B.Column_Name
AND B.Table_Name = 'FY2007_DATA'
AND B.Table_Schema = 'dbo'
WHERE
A.Table_Schema = 'dbo'
AND A.Table_Name = 'FY2006_DATA'
AND (A.Column_Name IS NULL OR B.Column_Name IS NULL)
Any help will be greatly appreciated
|
|
|
|
|

|
im using a delay on user input
it accept the user input after a second
but whenever it try to do
what it suposed to do it crash
heres my code
{
bool timedOut2 = TBDelay2.EndInvoke(res2);
if (timedOut2)
Dispatcher.CurrentDispatcher.Invoke(
new ActionToRunWhenUserStopstyping2(DoWhatEverYouNeed2),
DispatcherPriority.Input);
}, null);
--
private void DoWhatEverYouNeed2()
{
Random r = new Random();
int n = r.Next();
var page4 = new TabPage(roombox.Text);
tabControl1.TabPages.Add(page4);
tabControl1.SelectedTab = page4;
var browser = new WebBrowser();
browser.Visible = true;
browser.Left = -browser.Width;
browser.ScriptErrorsSuppressed = true;
browser.Dock = DockStyle.Fill;
browser.IsWebBrowserContextMenuEnabled = false;
page4.Controls.Add(browser);
browser.Name = roombox.Text;
page4.Name = roombox.Text;
browser.Navigate("http://www.tinychat.com/" + roombox.Text)
}
|
|
|
|

|
...and the exception message would be ....... ?
and on which line does it throw?
|
|
|
|

|
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.
at this line
Dispatcher.CurrentDispatcher.Invoke(
new ActionToRunWhenUserStopstyping2(DoWhatEverYouNeed2),
DispatcherPriority.Input);
|
|
|
|

|
also i just updated my visual studio and i get much better detail about the crash
Cross-thread operation not valid: Control 'tabControl1' accessed from a thread other than the thread it was created on.
|
|
|
|

|
as the first lines of your DoWhatEverYouNeed2 method, use
if (InvokeRequired)
{
this.Invoke(new MethodInvoker(DoWhatEverYouNeed2));
return;
}
|
|
|
|

|
well thx alot now everything works but it still seems to be a quit demanding task
is there any way to relief the pressure or its best to leave it that way
|
|
|
|

|
after trying it heavily everything works smoothly is there any way u could
elaborate on why this code all of suden makes everything work
|
|
|
|

|
You can NOT touch a control from anything other that the thread that created it. The UI (or startup) thread owns the controls and touching them at all (even so much as setting a property value) from anything other than the UI thread will fail with unpredictable results.
|
|
|
|

|
Do some error handling in DoWhatEverYouNeed2() - at least, show the exception message and stacktrace in a messagebox or write them to a log file.
|
|
|
|

|
hi thx for u reply where should i put the exeecption handling
in the code i showed
|
|
|
|

|
In a C# 2010 desktop application, I would like to come up with a test to see if the value 'CUST' is a valid directory level within a directory path supplied to the program. Basically the directory path would look like:
"C:\RData\CUST\Omaha\book.xlsx".
The code I am using the following code, but it is not working:
string filesaveLocation=ConfigurationSettings.AppSettings["Location"];
if (filesaveLocation == "*CUST*").
The value for filesaveLocation is obtained from the app.config file.
Thus can you show me how to change the code listed above, so that I can verify that 'CUST' is one of the directory folder names listed in a file path that looks like "C:\RData\CUST\Omaha\book.xlsx"?
|
|
|
|

|
You can use the String.Contains() method to check the path:
if (filesaveLocation.Contains("CUST"))
Or if character casing matters:
if (filesaveLocation.ToUpper().Contains("CUST"))
Or if you want to check for a directory named "CUST":
if (filesaveLocation.Contains(@"\CUST\"))
Good Luck!
-NP
Never underestimate the creativity of the end-user.
|
|
|
|

|
You can use the function System.IO.Directory.Exists(myFolderPath) for the same
|
|
|
|

|
Try:
if (filesaveLocation.Contains(@"\CUST\"))
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|

|
Thank you for your replies.
I also have to test to see if the directory file path does not = 'CUST', in the directory path called ""C:\RData\CUST\Omaha\book.xlsx". How would you code that change?
|
|
|
|

|
Uhhhh, you're question isn't really clear, but wouldn't the same test work with just the smallest change??
if (filesaveLocation.Contains(@"\CUST\") == false)
|
|
|
|

|
Morning Dave!
Do you need more coffee?
if (!filesaveLocation.Contains(@"\CUST\"))
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
|

|
You're welcome!
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|

|
Note that what you are doing here (and what the replies show you how to do) is checking for the presence of a string within another string.
Checking for the "validity" of a Directory, its actual existence, when your program is running, before you take some action, like writing a file to that Directory, is another thing. .NET hands you some excellent tools for checking whether Directories, or Files, actually exist.
The System.IO library offers a host of static methods such as File.Exists("file path"), Directory.Exists("directory file path") to check run-time existence. And, for more complex purposes, you can create an instance of a DirectoryInfo object, which has Properties like .Exists.
There are several reasons that these functions could return 'false: some are obvious, like the fact that the Directory/File doesn't exist any more; others more subtle, like you have some invalid character in the path name.
Based on your questions, I suggest you get a good basic book on C# programming, and study the different operators you can use with a 'string object.
And then, think about what you are going to do if the string you have in your Application Settings is incorrect: that will take you into studying the tools offered by the System.IO library.
Study, experiment, practice, analyze your errors: learn
yours, Bill
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|

|
Hi
I have a to make space invaders for school.
I can move the defender with the mouse and he also shoots with a mouse click but I also want to use the keyboard keys left, right and spacebar.
I don't know how to start for this, please help!
Thank you!
|
|
|
|

|
Hey derp,
Not sure how you think we can "start" it for you. I mean I guess I could send you my paypal info and that could "start" something, but since your requirements posted are quite minimal I will keep the rate nice and low (relatively low for a HW assignment atleast).
Ok seriously though, what makes you think we would do your homework for you? While people may 'help' you with their homework (they will likely keep in very minimal... It is for you to learn not us to do) you have not posted ANYTHING that you tried. Stating you can get it to move with this and that but not what your assignment is will not get you anywhere even if someone were willing to do the entire assignment for you.
Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.
|
|
|
|

|
You don't have to do my homework :s I just can't find how to use keyboard keys instead of a mouse control...
This is my project http://pastebin.com/DVewwGmz[^]
|
|
|
|

|
Well, then, it looks like you haven't looked through the list of events for the Form class. I wonder what the KeyDown and KeyUp events are for...
|
|
|
|

|
There are a couple ways you can capture keyboard keys.
First which is more acceptable and easier is dependent on your UI stack (WPF, WinForms etc.)
Each have specific events they can listen to that you create from the UI/Design side and is pushed into your logic.
For example if it is WPF you can add the KeyDown and KeyUp events to any UIElement (window, custom control, textbox etc.)
You will then create (or auto create) an event in your code behind like this:
private void UserControl_KeyDown(object sender, KeyEventArgs e)
{
}
The other is to make more of a global hook. A developer does this if they must capture all keys regardless of where the focus is (e.g. multiple window system but I need Ctrl+5 to do something specific)
Here is a decent blog post on how to do that.
http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx[^]
Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.
|
|
|
|

|
Thank you Collin Jasnoch I will try that!
|
|
|
|

|
You're welcome and good luck
Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.
|
|
|
|

|
Hi All,
The Pen and the Brush objects' Color property needs to be set when they are created. The problem is the color values one can use is very limited. Is there a way to send the color code to the Pen or the Brush object dynamically after choosing a color from a palette? Thanks in advance for your reply.
modified yesterday.
|
|
|
|

|
You do that by creating a new Pen/Brush with that selected color (do not forget to Dispose() of the old Pen/Brush objects for freeing the resources).
|
|
|
|

|
Hi, thanks for responding. I was already aware of setting the color of the pen or the brush object using the Color.color name method. What I would like to do instead of using color names such as blue, green, red, etc. is pass in the RGB code to the property like the following
Pen myPen = new Pen;
myPen = System.Drawing.Color.F08080;
modified yesterday.
|
|
|
|

|
Have a look at the FromArgb[^] method of the Color struct, you can set it to anywhere in the 32bit ARGB range. So, you set the Color and pass that to the Pen...
Edit:
using(Pen pen = new Pen(Color.FromArgb(0)))
{
}
replacing the zero with the value you want
|
|
|
|
 |