|
Cheers Simon
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Pleasure.
Simon
|
|
|
|
|
DaveyM69 wrote: Is this sufficient?
I believe so. Correct me if I'm wrong, but don't the destructors automatically call base.Dispose ?
----modified
Saw Simon's reply. Learned something new this morning.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hey everybody
I wondered if there is a way to connect to word application without the running object table.
Meaning, instead of getting the COM object from the ROT, ask from running instance of word (queryInterface or something like that...).
Thanks a lot!
|
|
|
|
|
what I found out until now:
Using the following code we're creating in C# a word application.
This application creates a new process of "winword.exe" because we're not checking the ROT for already running instances of word.
Type T = Type.GetTypeFromCLSID(new Guid("{000209FF-0000-0000-C000-000000000046}"));
Word.Application app = (Word.Application)Activator.CreateInstance(T);
app.visible = true;
What I still couldn't find is a way to connect to the running word (without ROT).
all I have is the Process ID.
I want to connect Word without waiting until it registers the ROT (in word's focus out event).
Thanks again!
|
|
|
|
|
Hello all,
I am having a bit o problem and i need a simple, elegant fix.
The problem: I am uploading a file to a ftp using FtpWebResponse and the Write method from a ftpRequest. I need this file locked for reading until all content has been uploaded to the Ftp and the write method has stopped.
Another app. (actually the same, but on a different machine) will download this file, and i need to read it only when the write method has stopped.
So far, my solutions do not work fully or are very very ... ugly
Thx
|
|
|
|
|
Hi,
If you're using Open-method on File class use FileShare.None for share parameter. This should prevent opening the file elsewhere.
Mika
|
|
|
|
|
How does the consumer process know there is a file to process?
And does the consumer use FTP to download the file, or is it on the machine your producer is
uploading to?
|
|
|
|
|
The consumer searches the ftp for a list of files with a given extension. (but it can also grab all the files from ftp, regardless of the extension. This part is configurable)
|
|
|
|
|
Here are some ways to consider:
1. have the consumer wait for a signal, and once it receives the signal make a list of available files,
then signal back to the producer; in between the consumer should not start creating new files.
2. have the producer use a fake extension, and once the file is uploaded, have it rename the extension;
3. have the producer a file, and once the file is uploaded, have it signal the consumer while
mentioning the file name.
As for signal, you could use anything available, including the creation and deletion of a file
that simply contains a filename.
My favorite would be 3, i.e. producer creates a file say file1.ext1, then it creates file
"currenttime.signal" containing the text "file1.ext1"; consumer would find all signal files,
read them, delete them, and process the file mentioned in them.
And I would use yyyyMMdd_HHmmss format for currenttime, so the signal files have identical alphabetical
and chronological order.
PS: if you are afraid two files need could be generated in the same second, just add a 2-second
delay in the producer code!
|
|
|
|
|
Thanks Luc.
The signal idea has crossed my mind, but not in such a superb manner .
I was afraid i would have to modify quite a lot, and that is not far from truth.
I retrospective, the whole architecture of the program should be reconsidered . Hopefully i'll have the time to do just that, and then i will implement your solution.
Thx all.
|
|
|
|
|
You're welcome.
|
|
|
|
|
I am making a simple chess game in my spare time. I have been thinking of the best way to check whether or not a move is valid for a certain piece.
Each "board square" has an index: 0 to 64. I have decided that when the player wants to make a move, I'll build a list of indexes that that piece can move to, and check whether or not the new position is in that list.
So, does anyone know of a better/easier way of checking the above?, i thought I'd post here before i crack on and see if anyone had any other ideas than me - thinking out of the box and all that. Cheers.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
|
enginço,
I don't want a complete game, as i want to learn, not copy. Also, the code looks horrible to say the least...
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi Gareth,
there are many ways to generate and store chess moves, I tried some of them.
The most popular nowadays has the following characteristics:
- use BOARD (a uint, that's unsigned int 64-bit) as the fundamental data type, and let each bit
represent one square.
- use as many BOARD items as you see fit, e.g. one to indicate the position of all white pieces,
one to indicate the position of all white rooks, etc.
- apply bitwise operators all the time: hence pieces=kings|queens|rooks|bishops|knights|pawns
- for move generation, try to use shifts, e.g. if wrooks is a BOARD indicating the position of
white rooks, then they could move one to the left by shifting left by one, except of course for
rooks in the "a" file; so it would look like wrooksLeft1=(wrooks & notAFile) << 1
- doing it this way, you can get very compact code, and avoid a lot of conditional branches and bugs.
- you have to work iteratively for long moves, so rookLeft7 does not make sense, you must iterate
with rookLeft1 since you have to detect occupied squares.
- you can't check yourself; the easiest way to avoid that is make your king behave as a queen, then
as a knight, and see whether it can capture a corresponding piece of the opposing color.
- and of course a lot of BOARD items can be precalculated and stored in some tables.
In my estimate it takes around a thousand lines of code to generate all moves correctly, including
castling, double pawn move, and en-passant.
Hope this helps.
modified on Monday, July 28, 2008 10:44 AM
|
|
|
|
|
I don't play chess however...
What I would do is use an OOP design approach.
The board can be an object that contains information relating to which piece is where.
I would have each type of piece as an object, as well, that has methods associated with it. Each method can then return a valid or invalid move and fire an event that the board object could then act on if the method returns a valid move.
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Hi Guy,
that is all pretty nice, but computer chess is about performance. You simply cannot afford to waste
cycles on calling virtual methods and the like if the strength of your computer game is all that
matters. You really have to make the best use of the number of CPU cycles you are allowed.
So OOP is fine for the GUI part of a chess game, but not for the chess engine itself.
That is assuming the end goal is a chess playing program; for pure validation and visualization,
every approach is fine, and then of course OOP is recommended.
|
|
|
|
|
Thanks - I appreciate that as I sometimes forget that the object interface provided is not necessarily the fastest or most efficent way to do things.
Coming from a very heavily procedural background, and having been seduced by OOP, I can sometimes assume that OOP will solve everything.
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
I have a variable passed into a method as an object. The object type is SQLDBType, I need to test the variable to find out what type it is, not the SQLDBType but the underlying eg varchar datetime (specifically I want to test wether the variable id datetime. Can someone please supply the syntax to find out if the dbtype is datetime
I am currently using the string comparison to "DateTime". However I then want to test the value of the datetime content (checking for #12:00:00# = no date) and falling in a hole.
public SQLParameter CreateParameter(string sParameterName, SqlDbType oDataType,
object oValue, int iLenght, ParameterDirection oDirection)
{
SQLParameter oParam = new SQLParameter();
oParam.ParameterName = sParameterName;
oParam.Length = iLenght;
if (oDataType.ToString() == "DateTime")
{
if (oValue == DBNull.Value)
{ oParam.Value = oValue; }
else
{
oDT = DateTime.Parse(oValue.ToString);
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
SqlDbType is an enum. So you can do:
if (oDataType == SqlDbType.DateTime)
{
}
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
AAaahhh - I hate it when it is the simple answer and I have spent the day looking for a complex one. Thanks.
Now how to test whether the value of an object variable is the min date (presumable #12:00;00#)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi All,
I am trying to scrape data from a site.
I have created a Window Form Application with Web Browser control and accessing its form element using like:
HtmlElement heleDay = wbPage.Document.GetElementById("cboDate_Day");
Now this application is working file but its really slow as entire page is to be loaded visually then I can do anything (parsing).
Then I realised that using HTTPWebRequest or WebClient I can do this in faster way. I have tried every thing but its not working.
Actual Page posts for like this:
document.frmStatus.action = "getstatus.asp"
document.frmStatus.submit()
and on this form there is one text box, 3 combo (for date) and one submit button.
Regards
Kumar
|
|
|
|
|
I guess my question is clear? or Posted at correct place?
|
|
|
|
|
I have a problem with the validating event of the datimepicker-control. I use this event to check the correct value of the date i.e. the inputed date shouldn't be in the past. Normally it works fine, but if you manually change the date via keyboard and leaving the control pressing the TAB key, the property 'Value' of the datetimepickers holds the old value. But this only happens, if you i.e. change the month from '01' to '2'. Changing the month from '01' to '02' is working correctly.
Any ideas why this is happening and how to resolve it?
|
|
|
|