|
The problem (as mentioned above) is your curly braces - the last two are commented out, as is should by them being coloured green.
If you get this kind of problem, Try CTRL+K CTRL+D - it formats your code so that everything is indented nicely. It won't work when you have missing braces, but if you fix that and try it, it should be obvious in future where things are going wrong.
BTW: You can change how Visual Studio handles your indentation to your preferred style in "Tools...Options" and then "TextEditor", "C#", "Formatting", "Indentation".
So if you prefer 1TBS:
if (condition) {
statement;
statement;
} Or K&R:
if (condition)
{
statement;
statement;
} Or Whitesmiths:
if (condition)
{
statement;
statement;
} You can get it to work with it happily. (I prefer Whitesmiths)
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thank you very much for the guidance. I will make the necessary adjustment in Visual Studio.
I appreciate you taking the time to help.
|
|
|
|
|
K&R is for real programmers good sir...
|
|
|
|
|
Nah. It's clumsy and inconsistent with single statement indentation:
If you write like this:
if (condition)
statement; Why would you change the indentation when it is a block you are using instead of a single statement?
if (condition)
{
statement;
statement;
} It's up to personal preference (or company practice) though - the important thing is to be consistent throughout.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I prefer K&R to 1TBS (devotees of both cults can be fanatics), because I think it's more readable, and more easily maintainable. WhiteSmith's I've never personally seen used at any place I've worked.
I maintain two simple macros in UltraEdit that will convert K&R<=>1TBS, if I should ever need to.
But, I think your "shibboleth" example code is a bit mis-leading: nothing stops you from using "pure" K&S and writing:
if(condition}
{
statement;
} Or even:
if (condition) { statement; } I've asked the braces directly how they feel about having only one statement, and they assure me they do not feel neglected or lonely
I think lack of braces around one simple and short statement, following an if-clause is seldom written with braces no matter what style of formatting you use.
Where omitting the braces would really "bother" me would be when the the single statement following the if-clause was so bloody long that it overflowed the text-working-area boundaries to be several lines long !
But, of course, you are, as usual, bulls-eye-center, when you emphasize you may not have personal choice if you go to work on some project where there are code formatting guidelines in place for all team members.
Thank goodness C# does not allow multiple statements separated by colons, or "line-continuation" characters, as in the late Pleistocene when VB roamed the savannas, and real men did not eat quiche and programmed only in C and assembly language.
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Personally, I use braces round single statements, but then I grew up without auto-indenting IDEs, so it was too easy to get caught by assuming logic flow from the indentation:
if (condition)
statement;
statement; Which is one of the reasons I really dislike 1TBS: it can be far to easy to miss the opening bracket, particularly if the condition is quite long.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I prefer
if(condition) statement;
and
if(condition){
statement;
statement;
}
Only for a limited set of statement lengths (or a long condition) will I do
if(condition_which_is_quite_long)
statement;
|
|
|
|
|
Hello All,
Lately i saw people using the scrabulizer app, which "helps" you with the game wordfeud
for the ones not familiar with wordfeud .. it is based on the old fasioned "scrabble" game two players having stones with characters playing turn by turn trying to mke words on the playing board
the app recognizes the characters(bitmaps?) on your screen (the playing board is a grid)
and suggests the best word you can make
it would be a real challenge for me writing such an app on my own
it is a concept usable for all kind of cardgames mah-yong etc etc.
It would be a long term time consuming project, which can of course be split into all different modules
the module i would like to start with is making a grid on my screen
(a1 - k12 or something like that) in some of the boxes there will be playing cards. i would like to compare every box with a known set of playing cards (eg bit maps) and on every positive match i would like to return which card is in the box
eg it returns a5 - 9H if there is a nine of hearts in box a5
at this moment i have no clue on how to detect a known image anywhere on the screen, is there someone who can give me a hint on what search terms to google for?
thanks in advance
Jan-Willem
|
|
|
|
|
It seems like doing image recognition is the wrong approach. It's hard and unnecessary when your program is generating the board, i.e. your program ALREADY knows which playing card is in each box.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
Sorry for my bad expression in english
The image on the screen is not from my software
the app i want to write finds an image on the screen that is placed there by a 3rd party software (eg a cardgame)
|
|
|
|
|
The fastest way to identify the image is using Bitmap.GetPixel () to distinguish the bitmaps from each other. You need to get a sample of each image, then find pixels that are different between the images.
Ideally you'll find one pixel that has a different value for every image. If there isn't one, start with the pixel that has the most different values for the different images, and make a decision tree, with branches for each unique value.
For example,
GetPixel () ----> Green
----> Red
----> Blue...
Then in each image group (branch) that has the same color, test another pixel to separate these cases:
Green ----> Light Green
----> Dark Green
----> Lime Green...
Using a program to play an online game is creative. People have been doing this in the stock market for a long time.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
|
What a waste of time: to hack someone else's software screen display to allow some user to have a higher score than their own abilities can produce ! This is the software equivalent of using "loaded dice," or "a marked deck."
Liable to lead to re-runs of old movies set on riverboat casinos which involve dramatic showdown scenes
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Come on Peepz!!
The challange is not the cheating to get a higher score
on that case the easiest way would be finding a cheat on the net
The challenge is being able to make such a piece of software
Learning new functions and afterwards thinking "yeah i knew i could do that"
Probably it wil take much more time to create this than you ever plan to use it
but look at is as if it is a puzzle you want to solve
|
|
|
|
|
A third party application requires that text passed to it is encoded in codepage 1252.
In our C# applications, the user can enter any character in the (windows forms) textboxes. I want to check the input before sending the text to third party.
Example:
When a user enters "Šöµß", that's OK because all of the strange characters can be found in Windows-1252.
But "ру́сский" is not OK, cyrillic characters are missing.
How can I check that?
|
|
|
|
|
For one or more strings I would:
- get an instance of Encoding for the 1252 code page;
- set its EncoderFallback to a new EncoderFallbackException;
- then use its GetBytes() to do the conversion, possibly resulting in an Exception being thrown.
For an individual character, I might consider:
- just once: building a 256-byte byte array holding all possible byte values;
- just once: convert that to a Unicode string using an Encoding for cp1252;
- then just test the character(s) using string.IndexOf.
|
|
|
|
|
Thanks for this hint.
Only one caveat: the EncoderFallback property is write protected, it must be set in the constructor:
Encoding encoding = Encoding.GetEncoding(1252, new EncoderExceptionFallback(), new DecoderExceptionFallback());
|
|
|
|
|
I would just encode (bytes) to 1252 and then decode that back to UTF (C#). If the output is the same as the input then it is ok.
|
|
|
|
|
Hi all,
I have a problem in creating a Excel RTD Server using C#.
The application is laid out as follows:
A window application which is running .Net Remoting server on a tcp channel (let's call it DataFeedServer).
A dll which can call DataFeedServer to get the data (let's call it DataFeedClient). The communication between those DataFeedServer and DataFeedClient is two-way (using callback functions and delegates).
Then I tried to call the DataFeedClient dll from a test windows application (let's call it TestWinApp).
Then the application flow is:
TestWinApp calls DataFeedClient, DataFeedClient calls DataFeedServer, DataFeedServer fires an event in DataFeedClient and finally DataFeedClient fires an event in TestWinApp. And it's working fine.
Then MS Excel comes in for real world scenario. I put a dll for RTD interface which will be called by MS Excel and which will call to DataFeedClient.
Then the scenario changed to MS Excel RTD calls DataFeedClient, and DataFeedClient calls DataFeedServer. Then DataFeedServer tried to fire an event of DataFeedClient. But fails. No error. Just silently stopped at that stage. So there's no calling from DataFeedClient back to MS Excel. The direction of the data flow is only half of the route always.
I'm not so sure I'm explaining clearly enough and thanks for taking your time this far.
Actually, the very essential information I need to know is if it's possible to use IRtdServer and Two-way .Net Remoting (with callback functions and delegates). Any information source is gratefully appreciated too.
Thanks in advance.
Best regards,
Zaw Min Tun
|
|
|
|
|
How to call java within c#?. It would be helpful if we know the steps to use java code in C#?
|
|
|
|
|
I've never tried it myself, but I have heard good things about it: IKVM.NET[^]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
If you are talking about directly using Java code from within a C# application, you might want to look at JNBridge.
http://www.jnbridge.com/[^]
I've never used it and I have no idea how much it costs, but it has a good reputation. It seems to do the job pretty well from what I can gather.
If you are talking about reusing functionality but don't need direct integration then it might be easier (and cheaper) to write a wrapper that lets you talk between the two components, e.g. a web service or a call through a TCP socket or something like that. It depends what your requirements are.
|
|
|
|
|
The requirement is here. There are two methods available in java.
Zip(string sourcefolder, string targetloction, string zipfilename);
UnZip(string zipfilename, string targetfolder);
We need call these methods from C#. Is there any ways to achieve whitout using JNBridge
/3rd party?
|
|
|
|
|
You have a number of options:
- use third-party tool like JNBridge or IKVM or similar
- use a web service or other cross-process communication
- write your own wrapper DLL using JNI
I have no idea what your Zip/Unzip methods do, but one option (which I am sure you have considered) is to bite the bullet and rewrite them in C#. If the Java functionality isn't too complicated, this would be my preferred option if it was my project. Don't forget, you will need a JVM up and running in order to call the Java methods. They will not run natively in .NET.
|
|
|
|
|
Thanks for your suggessions. I will try to implement wrapper DLL using JNI.
|
|
|
|