|
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
No need to ask. Go ahead, please.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Gosh - it's been a long time since anybody mentioned Carrier Sense Multiple Access with Collision Detection. Good on you. What's your question?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
anooshe wrote: iwant to write CSMA/CD with c#
For what purpose?
|
|
|
|
|
What made you feel you needed to ask for permission ? If you ever have an actual programming question, I suggest you read the guide on how to ask questions, first.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi, I'm making a Bingo Generator for a assignment, but it generates the last number, then should you click the button again it crashes, also crashing VS2010 so I don't get a error either. here's the button code:
var lineCount = 1;
using (var reader = File.OpenText(@"saved.bingo"))
{
while (reader.ReadLine() != null)
{
lineCount++;
}
}
TextWriter saveCalled = new StreamWriter("saved.bingo");
saveCalled.Write(called.Text);
saveCalled.Close();
TextReader loadSaved = new StreamReader("saved.bingo");
string saved = loadSaved.ReadToEnd();
loadSaved.Close();
randomGenerated.generate();
TextReader nextBingo = new StreamReader("bingoNext.bingo");
string bingoNum = nextBingo.ReadToEnd();
nextBingo.Close();
bingoNum = bingoNum.Trim();
if (saved.Contains(bingoNum) == true)
{
randomGenerated.generate();
}
else
{
TextReader tr = new StreamReader("saved.bingo");
string saveNm = tr.ReadToEnd();
tr.Close();
int saveNum = saveNm.Count();
if (saveNum >= 15)
{
button1.Visible = false;
MessageBox.Show("Game Over.");
}
newnum.Text = bingoNum;
TextReader nextCalled = new StreamReader("calledNext.bingo");
string calledNum = nextCalled.ReadToEnd();
nextCalled.Close();
called.Text = calledNum;
}
and the generator code:
namespace openBingo
{
public class randomGenerated
{
public static void generate()
{
System.Random linegrab = new System.Random(DateTime.Now.Millisecond);
TextReader numRead = new StreamReader("numbers.bingo");
ArrayList lines = new ArrayList();
string line;
while ((line = numRead.ReadLine()) != null)
{
lines.Add(line);
}
int randomIndex = linegrab.Next(lines.Count);
string bingoNum = (lines[randomIndex]).ToString();
numRead.Close();
TextReader numbCheck = new StreamReader("saved.bingo");
string saved = numbCheck.ReadToEnd();
saved = saved.Trim();
numbCheck.Close();
if (saved.Contains(bingoNum))
{
randomGenerated.generate();
}
else
{
TextWriter saveNum = new StreamWriter("saved.bingo");
saveNum.WriteLine(bingoNum);
saveNum.Close();
string randBingo = bingoNum;
TextWriter subNum = new StreamWriter("bingoNext.bingo");
subNum.WriteLine(randBingo);
subNum.Close();
string newCalled = saved + " " + randBingo;
TextWriter subCol = new StreamWriter("calledNext.bingo");
subCol.WriteLine(newCalled);
subCol.Close();
}
}
}
}
It also gives no error on compiling either.
Thanks in advance, any more info you need to just say.
Ben.
|
|
|
|
|
Wrap the code in try/catch block and print out the exception.
Best wishes,
Navaneeth
|
|
|
|
|
Hi,
you need to figure out where things go wrong. Start by using a try-catch block, and displaying the exception, all of it. Hence use something along these lines:
try {
} catch (Exception exc) {
Console.WriteLine(exc.ToString());
}
You can do this in the button click handler, in the generate() method, etc.
Then watch the line numbers (and tell Visual to always show them, see here[^])
BTW: your program looks terrible. Many things seem less than good.
- Why are you writing and reading files all the time? Don't you trust the computer's memory?
FYI: there are File methods that read or write all text of a file.
- For random numbers, you should only have a single RNG and call Next on it, instead of creating new ones.
- generate() is recursive. Any idea what keeps it from recursing forever? (which would cause a StackOverflowException).
- and please stop abusing the var keyword, use real types instead.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi again,
How would I store something in the computers memory?
Ben.
|
|
|
|
|
Normally you keep the data in variables as long as your app is running; and you save it to disk, if needed, when the app exits.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Haha, I do try, but sometimes i need to use the data of the variable in a diffrent button control or something, and it wont let it.
I tried settting it to something like:
public void button1
but no luck
Thanks,
Ben.
|
|
|
|
|
Ben Magee wrote: I tried settting it to something like:
public void button1
but no luckFrown
I think maybe you need to study the basics of C#.
|
|
|
|
|
Richard MacCutchan wrote: I think maybe you need to study the basics of C#.
Did some studying, I now understand I need a public class with static variables inside to store data.
Thanks for the advice (:
Ben.
|
|
|
|
|
Ben Magee wrote: I now understand I need a public class with static variables inside to store data.
I think my previous statement still stands. This is not the way to store data within classes or methods.
|
|
|
|
|
Ben Magee wrote: it generates the last number
Do you mean it goes through all the available numbers and then you try to get one more? When there aren't any more? Don't you want to reset at some point?
|
|
|
|
|
When the form loads, it generates all the numbers, and writes them to a file. When you press the button, it gets a random line from that file, and then the number on it, it then checks if the number is in a file with the numbers already called, if it isnt, it adds it to that file and then displays it.
Forgive me, I am still relatively new to C# - and I am looking up on sharing variables between classes now.
BtM.
|
|
|
|
|
Regardless of the implementation; once you've selected all the numbers, there are no more to select no matter how hard you try. You need to reset.
|
|
|
|
|
Hi all,
I have an asp.menu that is bound to a SiteMapDataSource. The web.sitemap file is built dynamically via the Session_Start method in global.asax. On each Session_Start a query is made to a table called "categories" in my database which contains all the sitemap data. This data is used to generate the web.sitemap file.
I've set a breakpoint and I actually see the web.sitemap file getting rebuilt everytime, however, even when the web.sitemap changes I see no change in the menu. It is not until I make a change to the web.config and save it that the changes to the web.sitemap are reflected in the menu. This tells me it is somehow getting cached.
Can someone please help??
Thanks!
Tim
|
|
|
|
|
i want to make c# program that can connect to the internet by using my mobile as modem,which i will insert "access point" and "user name "
provided by services company like "Fodafone"
please help me
|
|
|
|
|
Anyone who answers you will almost certainly do so after having googled. So why not do so for yourself, try to use what you find and only then ask here with a specific problem, showing the code that causes you a problem and stating the exact error/problem.
Hint: There are some articles here on Code Project that might help you.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I want to get the number of bytes written into or read out from my disk in the latest minuter.
But I hava no idea . Please do me a favor?
|
|
|
|
|
|
Thank you!
I have checked that class.There are only properties but no methods in it.I still hava no idea how to use it.can you give me a example to show me how to use that class to get what I want?
|
|
|
|
|
I am facing this problem 1st time. I've made a web service in VS 2005 and a windows client application which consumes it without any problem since long time.
Recently we decided to develop the new client application hence i decided to use VS 2008. I copied the methods from old application, which has code to call the web service methods. I added the web reference and I can see all the web service classes and methods in OBJECT BROWSER (by right clicking on the web service reference and clicking on View in Object browser). When I compile the application i get the error on the line where I am declaring the variables of classes in web service
MyAppNamespace.MyWebService.ClassName webObj;
Note that fully qualified name is in my code and same is shown in Object browser. But when I try to type the code in VS 2008, I can not see the web service name space (MyWebService) in intellisense any where. I opened the Reference.cs file of the web service, there also present same name space as i am using. I can open the Web service URL in browser and also old application is still working fine with web service.
Is there any body who can guide me what is wrong? Thanks in advance
Modified:
One thing more for your information. I've 2 projects in a solution. One is Windows Forms project and other is .NET Assembly project (to create the .NET assembly).
If I am adding web reference in Windows Forms project, it is working. i.e. I can use web service classes and methods, but if I add web reference to .NET assembly project, I can not, which is actual problem mentioned above.
Regards
Aftab Sindhi
.NET Application Developer
U.A.E
modified on Sunday, November 1, 2009 2:40 AM
|
|
|
|
|
Hi
I need send and receive information from "single COM port" to "2 COM port", We know COM has 9 pin and with only 3 pin you can send & receive into one device. So physically this is possible. and I want to know how can implement with C#.
Best Regards,
Reza Shojaee
|
|
|
|