|
hi,
i mean when i write
Thread myThread = new Thread(ThreadMethod);
it said
[Error 1 A field initializer cannot reference the nonstatic field, method, or property 'Interface.mainScreen.threadProcedure()' C:\Documents and Settings\Administrator\Desktop\Well Formed Interface_thread\Interface\mainScreen.cs 38 49 Interface
]
and i am actually want to know the reason that when i used abort it makes exception
and i want to ask if i can make the lockobject my thread name
thanx
-- modified at 12:02 Wednesday 11th April, 2007
Generator
-- modified at 14:19 Wednesday 11th April, 2007
|
|
|
|
|
How would I make a value from database reference the string value in the combobox. For example, 2 is the value from the database and the display value is "Las Value" How would do it? I can use select statement to get the string value but wondering if there is any other way.
|
|
|
|
|
Why don't you have a lookup list somewhere - in the database for example.
|
|
|
|
|
Hello All,
Currently I have developed an application using VC++ 6.0. Latter when "Developer Environment 2003" came I migrated to VC++.NET. But my code is fully like VC++ 6.0 code (I have not used .NET fully in my project)
I am planning to move this project to either C# or VC++. NET fully. I want your suggetion which will be better. Application uses MFC for GUI, Database, File operations, COM for communication between different modules and multithreading extensively. Suggest me which is better for such type of project C# or VC++.NET!!!
I want to have better GUI, easy DB Support, File oprations, easier COM communication and mainly Mulithreading and IPC should be easy. Memory leaks it is automatically taken care I can be more lazy .
Suggest me better option between 2.
Thanks
Ravi
|
|
|
|
|
On the areas you want to be easier to deal with C# is the obvious winner. However, you have to balance that with the migration cost.
|
|
|
|
|
Here is a straight forward question: Is it better to declare refrence values locally. For instance you have an object with two data types int. In your using object you need to use those continuously, do you use them from their source or do you create local primative types to hold their values.
Just curious which is the better practice and performance.
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
I have no idea what you mean by that. Could you provide code examples of what you mean?
|
|
|
|
|
This is more theoretical than anything else and I have heard variations.
Generally you have a class:
public class employee<br />
{<br />
string employeeName;<br />
int empID;<br />
<br />
(Some other methods)<br />
<br />
}
In the using class, say company you could just reference the employeeName through its class such as employee.employeeName. But if you need to continuously reference that name do you want to do this or do you want to do:
<br />
public class company<br />
{<br />
string employeeName = employee.employeeName;<br />
}<br />
Then use the local, or is it better to alway just call the employee.employeeName.
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
Oh, I see. Well, if it is something as simple as accessing a field then I don't think there is much advantage in saving it locally. Also, you really ought not to be accessing the fields of a class directly from outside the class in which it is declared.
If you are accessing a property then there possibily is an advantage is saving it locally. The property could, for example, have to do a look up each time it is called - That takes time, so it would be better if that didn't have to happen.
Often, I'll save the value locally for improved readability more than any other reason. All those excessively long lines can be difficult to debug, especially if you are stepping through code and you keep stepping in and out of properties in one line of code.
|
|
|
|
|
Thanks,
It really was a stupid question, one of those where for no reason you just wanna get an idea since you have always done something in a way but never wondered if it really made any difference. Kinda like stings and string builders. Truly makes a difference.
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
Hi,
How to invoke web service methods in C#.Net?
Thanks in advance
|
|
|
|
|
The question is a bit short to really understand your problem. But I will try to guess here.
The most basic operation to be able to use a webservice in your application is to right-click on the project and choose Add Web Reference. There you browse to the webservice, give it a good name and select OK.
After that it's just simply a matter of doing something like this:
ServiceClass service = new ServiceClass();<br />
object someResult = service.SomeMethod(someParameter);
The service class is strongly typed, so you shouldn't have much trouble finding out how to call the service and what to pass and what you get in return.
Hope this helps
WM.
What about weapons of mass-construction?
"What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson
|
|
|
|
|
I have a complex query.. with differnent tables...
n i want it to be displayed in my report viewer on my c# winform...
I want all formating and other coding to be done without using any GUI wizards for the report viewer.. Everything hardcored... and i want to have total control on the report viewer to display each an every item precisely where i want...
Plz... Help me I'm undergoing my academic project
and in badly need of it
me
vin'S
ww.vinsblogs.blogspot.com
VINAYAK J BADDI
www.vinsblogs.blogspot.com
|
|
|
|
|
All dear friends of this forum i'm asking you help.
I have to create simple poker game in console application.
I created already but this via functions. I need to create with structs this game. Plz help me. I can't succeed almost 2 weeks....
I understand that is hard question but this code is ready and it works
just how to create this in structs and not in functions
And how can i upload file to this forum.
arr[j + 1])<br />
{<br />
temp = arr[j];<br />
arr[j] = arr[j + 1];<br />
arr[j + 1] = temp;<br />
} <br />
}<br />
<br />
static void InitializeHand(int[] hand)<br />
{<br />
Random rnd = new Random();<br />
hand[0] = rnd.Next(0, 52);<br />
for (int i = 1; i < hand.Length; i++)<br />
{<br />
hand[i] = rnd.Next(0, 52);<br />
for (int j = i - 1; j >= 0; j--)<br />
if (hand[i] == hand[j])<br />
{<br />
i--;<br />
break;<br />
}<br />
} <br />
} <br />
<br />
static void PrintHand(int[] hand)<br />
{<br />
char sign = ' ';<br />
string card = "";<br />
int val;<br />
Console.WriteLine("Your hand:"); <br />
<br />
for (int i = 0; i < hand.Length; i++)<br />
{<br />
val = hand[i] / 13;<br />
switch (val)<br />
{<br />
case 0:<br />
sign = '♠';<br />
break;<br />
case 1:<br />
sign = '♣';<br />
break;<br />
case 2:<br />
sign = '♥';<br />
break;<br />
case 3:<br />
sign = '♦';<br />
break;<br />
}<br />
<br />
val = hand[i] % 13;<br />
switch (val)<br />
{<br />
case 0:<br />
card = "A";<br />
break;<br />
case 1:<br />
case 2:<br />
case 3:<br />
case 4:<br />
case 5:<br />
case 6:<br />
case 7:<br />
case 8:<br />
case 9:<br />
card = (val + 1).ToString();<br />
break;<br />
case 10:<br />
card = "J";<br />
break;<br />
case 11:<br />
card = "Q";<br />
break;<br />
case 12:<br />
card = "K";<br />
break;<br />
}<br />
<br />
Console.WriteLine("{0}.{1,3} {2}", i + 1, card, sign);<br />
}<br />
}<br />
<br />
static int[] GetPics(int[] hand)<br />
{<br />
int[] arr = new int[hand.Length];<br />
for (int i = 0; i < arr.Length; i++)<br />
arr[i] = hand[i] % 13;<br />
return arr;<br />
}<br />
<br />
static bool Flush(int[] hand)<br />
{<br />
if (hand[0] / 13 == hand[1]/13 && hand[1]/13 == hand[2] / 13 && hand[2] / 13 == hand[3] / 13 && hand [3] / 13 == hand[4] / 13)<br />
return true;<br />
else<br />
return false;<br />
}<br />
<br />
static bool Straight(int[] hand)<br />
{<br />
int[] pic = GetPics(hand);<br />
<br />
BubbleSort(pic); <br />
<br />
if (((pic[0] + 1 == pic[1]) || (pic[0] + 12 == pic[4])) && pic[1] + 1 == pic[2] && pic[2] + 1 == pic[3] && pic[3] + 1 == pic[4])<br />
return true;<br />
else<br />
return false;<br />
}<br />
<br />
static bool FourOfAKind(int[] hand)<br />
{<br />
int[] pic = GetPics(hand);<br />
<br />
BubbleSort(pic);<br />
<br />
if (((pic[0] == pic[1]) || (pic[3] == pic[4])) && pic[1] == pic[2] && pic[2] == pic[3])<br />
return true;<br />
else<br />
return false;<br />
}<br />
<br />
static bool FullHouse(int[] hand)<br />
{<br />
int[] pic = GetPics(hand);<br />
<br />
BubbleSort(pic);<br />
<br />
if ((pic[0] == pic[1] && pic[1] == pic[2] && pic[3] == pic[4]) || (pic[0] == pic[1] && pic[2] == pic[3] && pic[3] == pic[4]))<br />
return true;<br />
else<br />
return false;<br />
}<br />
<br />
static bool ThreeOfAKind(int[] hand)<br />
{<br />
int[] pic = GetPics(hand);<br />
<br />
BubbleSort(pic);<br />
<br />
if ((pic[0] == pic[1] && pic[1] == pic[2]) || (pic[1] == pic[2] && pic[2] == pic[3]) || (pic[2] == pic[3] && pic[3] == pic[4]))<br />
return true;<br />
else<br />
return false;<br />
}<br />
<br />
static bool TwoPairs(int[] hand)<br />
{<br />
int[] pic = GetPics(hand);<br />
<br />
BubbleSort(pic);<br />
<br />
if ((pic[0] == pic[1] && pic[2] == pic[3]) || (pic[1] == pic[2] && pic[3] == pic[4]) || (pic[0] == pic[1] && pic[3] == pic[4]))<br />
return true;<br />
else<br />
return false;<br />
}<br />
<br />
static bool Pair(int[] hand)<br />
{<br />
int[] pic = GetPics(hand);<br />
<br />
BubbleSort(pic);<br />
<br />
if ((pic[0] == pic[1] || pic[1] == pic[2]) || (pic[2] == pic[3] || pic[3] == pic[4]))<br />
return true;<br />
else<br />
return false;<br />
}<br />
<br />
static void CardReplace(int[] hand)<br />
{<br />
string s;<br />
do<br />
{<br />
Console.Write("How many cards would you like to replace (0-3): ");<br />
s = Console.ReadLine();<br />
} while (s != "0" && s != "1" && s != "2" && s != "3");<br />
<br />
int[] idxCardToReplace = new int[int.Parse(s)];<br />
for (int i = 0; i < idxCardToReplace.Length; i++)<br />
{<br />
do<br />
{<br />
Console.Write("Replace card ({0}/{1}): ", i + 1, idxCardToReplace.Length);<br />
s = Console.ReadLine();<br />
} while (s != "1" && s != "2" && s != "3" && s != "4" && s != "5");<br />
idxCardToReplace[i] = int.Parse(s);<br />
for (int j = i - 1; j >= 0; j--)<br />
if (idxCardToReplace[i] == idxCardToReplace[j])<br />
{<br />
Console.WriteLine("This card was chosen already");<br />
i--;<br />
break;<br />
}<br />
} <br />
<br />
int[] cardToReplace = new int[int.Parse(s)];<br />
Random rnd = new Random(); <br />
for (int i = 0; i < cardToReplace.Length; i++)<br />
{<br />
cardToReplace[i] = rnd.Next(0, 52);<br />
for (int j = 0; j < hand.Length; j++)<br />
if (cardToReplace[i] == hand[j])<br />
{<br />
i--;<br />
break;<br />
}<br />
for (int j = 0; j < i; j++)<br />
if (cardToReplace[i] == cardToReplace[j])<br />
{<br />
i--;<br />
break;<br />
}<br />
}<br />
<br />
for (int i = 0; i < idxCardToReplace.Length; i++) <br />
hand[idxCardToReplace[i] - 1] = cardToReplace[i];<br />
}<br />
<br />
static int PrintHandRank(int[] hand)<br />
{ <br />
int[] tmpHand = new int[hand.Length];<br />
for (int i = 0; i < hand.Length; i++)<br />
tmpHand[i] = hand[i];<br />
BubbleSort(tmpHand);<br />
<br />
Console.Write("Rank: ");<br />
if (Flush(tmpHand) && Straight(tmpHand))<br />
{<br />
Console.WriteLine("Straight flush");<br />
return 10;<br />
}<br />
else if (FourOfAKind(tmpHand))<br />
{<br />
Console.WriteLine("Four of a kind");<br />
return 7;<br />
}<br />
else if (FullHouse(tmpHand))<br />
{<br />
Console.WriteLine("Full house");<br />
return 6;<br />
}<br />
else if (Flush(tmpHand))<br />
{<br />
Console.WriteLine("Flush");<br />
return 5;<br />
}<br />
else if (Straight(tmpHand))<br />
{<br />
Console.WriteLine("Straight");<br />
return 4;<br />
}<br />
else if (ThreeOfAKind(tmpHand))<br />
{<br />
Console.WriteLine("Three of a kind");<br />
return 3;<br />
}<br />
else if (TwoPairs(tmpHand))<br />
{<br />
Console.WriteLine("Two Pairs");<br />
return 2;<br />
}<br />
else if (Pair(tmpHand))<br />
{<br />
Console.WriteLine("Pair");<br />
return 1;<br />
}<br />
else <br />
Console.WriteLine("Highest Card");<br />
return 0;<br />
}<br />
<br />
static int CalcPoints(int bet, int mult, int total)<br />
{<br />
switch (mult)<br />
{<br />
case 0:<br />
Console.WriteLine("You lost {0} points.", bet);<br />
break;<br />
case 1:<br />
Console.WriteLine("No win no lose.");<br />
break;<br />
default:<br />
Console.WriteLine("You won {0} points.", mult * bet);<br />
break;<br />
}<br />
total += bet * mult;<br />
Console.WriteLine("Total points: {0}", total);<br />
return total;<br />
}<br />
<br />
static int GetBet(int total)<br />
{<br />
int bet;<br />
Console.WriteLine("Total points: {0}", total);<br />
do<br />
{<br />
Console.Write("Enter bet (1-{0}): ", total);<br />
bet = int.Parse(Console.ReadLine());<br />
} while (bet < 1 || bet > total);<br />
return bet;<br />
}<br />
<br />
static void PrintMenu()<br />
{<br />
Console.WriteLine("Poker Project:");<br />
Console.WriteLine("-------------------");<br />
Console.WriteLine("(1) Play");<br />
Console.WriteLine("(2) Exit");<br />
Console.Write("Enter your choice: ");<br />
}<br />
<br />
static void HandleUser()<br />
{<br />
int[] hand = new int[5];<br />
<br />
string choice;<br />
int total = 100;<br />
int bet;<br />
int mult;<br />
<br />
do<br />
{<br />
Console.Clear();<br />
PrintMenu();<br />
choice = Console.ReadLine();<br />
Console.WriteLine();<br />
<br />
switch (choice)<br />
{<br />
case "1": <br />
bet = GetBet(total);<br />
total -= bet; <br />
Console.Clear();<br />
InitializeHand(hand);<br />
PrintHand(hand); <br />
mult = PrintHandRank(hand);<br />
CardReplace(hand);<br />
PrintHand(hand); <br />
mult = PrintHandRank(hand);<br />
total = CalcPoints(bet, mult, total);<br />
if (total == 0)<br />
{<br />
Console.WriteLine("Game Over.");<br />
goto case "2";<br />
}<br />
break;<br />
<br />
case "2":<br />
Console.WriteLine("Thank you for playing poker.");<br />
choice = "2";<br />
break; <br />
<br />
default:<br />
Console.WriteLine("Choice {0} is invalid, please try again..", choice);<br />
break;<br />
}<br />
Console.Write("Press Enter to continue..");<br />
Console.ReadLine();<br />
} while (choice != "2");<br />
<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
HandleUser();<br />
}<br />
}<br />
}
|
|
|
|
|
When you posted this and you got the warning that your message was very long and you should consider cutting it down, did you actually pay any attention?
I'd love to help, but I'm not going to read through all that. If you have a specific question then we'd love to help.
One quick comment. Your first method is a bubble sort. What was wrong with the built in sorting mechanisms in .NET?
|
|
|
|
|
Colin Angus Mackay wrote: I'd love to help, but I'm not going to read through all that. If you have a specific question then we'd love to help.
I've started helping out here on somewhat of a regular basis. I've noticed that posters rarely surround their code with pre tags. Instead, they use the code tag or no tag at all. This makes it hard to read their code.
|
|
|
|
|
Leslie Sanford wrote: I've noticed that posters rarely surround their code with pre tags. Instead, they use the code tag or no tag at all.
The problem, and it's something you should take up with Chris if you want anything done is that the pre tag doesn't appear to be intended for code snippets. I'm not sure what to rename it as to make what it and the code tag are intended to do more clear, otherwise I'd've posted to the suggestions board a while ago myself.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
Yes Colin i saw this warning about long code and i appoligize for that.
May be you are right about bubble sort and it's not be included in code.
My question how to rebuilt this code in "structs". I began programm 4 months
ago and i don't have a lot of skills. But i have to rebuilt this to struct.
i want to do 3 or 4 structs : " Card", "CardDeck", "Hand" and may be "Game".
Card and CardDeck i think allright, but Hand that initializes 5 cards prints
and replaces old card to new not working, i don't know what to do.
May be somebody know source code or links to this.
Tnanks...
|
|
|
|
|
You could have a look at my article [^]about scoring cribbage hands.
Cribbage is a fundamentally different card game from poker, but I show you how to find pairs, flushes and straights...
Share and enjoy.
Sean
|
|
|
|
|
I did it already and i know how to find pairs but i've got confused
how to rebuilt it structs my brother
|
|
|
|
|
Hi,
From database i m getting value like 1,2,3,4,5,6,7,8,9,10,11 upto 9999.
these value i m displaying in combobox
but i want to display like this
if it's 1 to 9 then i have to display 0001.
if it's 10 to 99 then i have to display 0010 upto 0099.
if it's 100 to 999 then i have to display 0100 upto 0999.
if it's 1000 to 9999 then i have to display 1000 upto 9999.
help me it's too urgent.
thanks
asif
|
|
|
|
|
Well I haven't worked with comboboxes but I believe they have two properties, datatextfield and datavaluefield. If so you can do this
combobox.datatextfield = datatable["field"].ToString().PadLeft(4,'0');
-----
|
|
|
|
|
comboBox1.Text = comboBox1.Text.ToString().PadLeft(4, '0');
|
|
|
|
|
hi,
i am using Datagrid view in my project..
and i have got 3 columns..
but in one of the 3 columns i want formated data in one of the column like..
000.000.000.000
user should enetr the number only..
how can do it..
pls help me
With Regards
prasad
|
|
|
|
|
Gents,
I have a combobox that contains operations (Range, >, < and =). The user should select needed opertion to process some text fields. How can I get the operation selected to put in the if statment. For example, here is a '>' is selected:
if (DoubleA > DoubleB)
I want to do it in efficient way because i have many comparisons based on user selection.
Thanks for your assistance in advance.
|
|
|
|