C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-23-2005, 03:19 PM   #1
Registered User
 
Join Date: Aug 2004
Posts: 731
how do I perform an action over and over...

I have this code...

Code:
namespace Drug_Wars
{
    partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            int health = 100;
        }

        textBox_health.Text = health;
    }
}
I am using visual c# 2005 beta. I have created the textbox and I want to put the varible health in the textbox so it draws the variable health. But I get an error when I put textBox_health.Text = health; at that spot. Where should I put it?
Rune Hunter is offline   Reply With Quote
Old 02-24-2005, 03:27 AM   #2
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
First, your "health" has to be a class scope variable. Right now, it's scope is the constructor. Outside the constructor, no "health" exists.

If you want an event to occur whenever "health" is changed ( for example putting the new value in the textbox ) a property would be fine. The set method could set the textbox ( for simplicity ) or call an OnHealthChanged Event. But I guess that's a bit much, so as step one, declare "health" in the scope of your form like this

Code:
namespace Drug_Wars
{
    partial class Form1 : Form
    {
        private  int health = 100;

        public Form1()
        {
            InitializeComponent();
            textBox_health.Text = health.ToString();
        }
     }
}
and move your textbox setting line into a function. A class can never have a line that is not a variable declaration outside of a function.
__________________
hth
-nv

She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

When in doubt, read the FAQ.
Then ask a smart question.
nvoigt is offline   Reply With Quote
Old 02-24-2005, 08:54 AM   #3
Registered User
 
Join Date: Aug 2004
Posts: 731
ok I fixed the varible. But the onHealthChanged event didn't work.

Code:
private void onHealthChanged()
{
      textBox2.Text = health.ToString();
}
maybe I did I somthing wrong cause I am new to c# but that doesn't work.
Rune Hunter is offline   Reply With Quote
Old 02-24-2005, 09:09 AM   #4
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
Well, you will have to implement the event yourself. Start by creating a property for Health.
__________________
hth
-nv

She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

When in doubt, read the FAQ.
Then ask a smart question.
nvoigt is offline   Reply With Quote
Old 02-24-2005, 09:12 AM   #5
Registered User
 
Join Date: Aug 2004
Posts: 731
ok well umm....

creating a property huh?

like I said I am new so umm.... how do you do that?
Rune Hunter is offline   Reply With Quote
Old 02-24-2005, 09:52 AM   #6
Registered User
 
Join Date: Aug 2004
Posts: 731
while I am on this topic, I don't want to start a new topic, I have anouther question.

Why can't any of my friends (running windows xp and some sp and other sp2) nto able to run my programs I made with visual c#. They get an error somtimes saying missing a dll or a memory error or somthing but there computer works fine.

Is it because I have .net framework 2.0 beta 1 and not 1.0 installed?
Rune Hunter is offline   Reply With Quote
Old 02-24-2005, 04:13 PM   #7
Registered User
 
Join Date: Mar 2002
Posts: 4
Quote:
Originally Posted by Rune Hunter
while I am on this topic, I don't want to start a new topic, I have anouther question.

Why can't any of my friends (running windows xp and some sp and other sp2) nto able to run my programs I made with visual c#. They get an error somtimes saying missing a dll or a memory error or somthing but there computer works fine.

Is it because I have .net framework 2.0 beta 1 and not 1.0 installed?
Programs compiled with Visual C# 2005 Beta depends on .NET Framework 2.0 beta. Your friends will need to install it inorder to run the programs you compiled.

Version 1 and 2 .NET Framework should happily co-exist on the same machine. Mine does
Jarad is offline   Reply With Quote
Old 02-24-2005, 06:22 PM   #8
Registered User
 
Join Date: Aug 2004
Posts: 731
dang it! This is sooooooo not cool.

Well it appears some stuff don't even work with visual c# 2005 beta.

So what do you recomend that uses 1.0 framework. I mean is there anouther free version of vusual C# that uses framework 1.0?
Rune Hunter is offline   Reply With Quote
Old 02-24-2005, 07:48 PM   #9
Banned
 
nickname_changed's Avatar
 
Join Date: Feb 2003
Location: Australia
Posts: 986
www.icsharpcode.net/OpenSource/SD/ uses the .NET Framework 1.1 runtime (the most common version). It's open source, you might give it a try.
nickname_changed is offline   Reply With Quote
Old 02-24-2005, 07:52 PM   #10
Banned
 
nickname_changed's Avatar
 
Join Date: Feb 2003
Location: Australia
Posts: 986
And there are no free versions of Visual C#, the one you have is only free at the moment because it's beta.

My recommendation would be to get a book about C# that will teach you why what you have done isn't working. Or you might like to read this:
http://www.softsteel.co.uk/tutorials/cSharp/cIndex.html
nickname_changed is offline   Reply With Quote
Old 02-24-2005, 07:54 PM   #11
Registered User
 
Join Date: Aug 2004
Posts: 731
maybe c# isn't for me then. Cause I hate sharp devolpe. I just can't stand it. I fallowed your link and tried it again but nope, I just don't like it.

I am guessing you eithe cna't get visual c# 2003 or it costs money then.




EDIT: And I do have a book on c#.

Last edited by Rune Hunter; 02-24-2005 at 08:22 PM.
Rune Hunter is offline   Reply With Quote
Old 02-24-2005, 08:23 PM   #12
Banned
 
nickname_changed's Avatar
 
Join Date: Feb 2003
Location: Australia
Posts: 986
A couple of thousand dollars I think. Do a search for Visual Studio 2003 60 Day Trial though, depending on where you live they may be able to post you a free trial pack.

Don't hate C# because you don't like the IDE's, it is a very good language and if you take the time to learn it you will come to love it. And don't expect to understand it all in a few days either - I work with people who have been using it for the past two years and are still learning new things. Programmers wouldn't get paid so much if anyone could pick up Visual Studio and write MS Word in 2 days.
nickname_changed is offline   Reply With Quote
Old 02-24-2005, 08:26 PM   #13
Registered User
 
Join Date: Aug 2004
Posts: 731
lol it ins't because I don't know c#. And I do love the lang.

Just that sharp devlope gives me an error I didn't create, and I just don't like it. Maybe if the product worked right I would like it, but right now I am not sure what to do.

I found visual c# 2003 standard for abnout 80 dallors on amazon, but does 2003 use .net 1.1? or 1.0?
Rune Hunter is offline   Reply With Quote
Old 02-24-2005, 09:53 PM   #14
Super Moderator
 
Join Date: Sep 2001
Posts: 4,746
Quote:
does 2003 use .net 1.1? or 1.0?
I've got a copy that appears to use 1.1, but I imagine it's quite updatable anyway, especially between minor version numbers.
sean is offline   Reply With Quote
Old 02-25-2005, 04:39 AM   #15
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
Quote:
Just that sharp devlope gives me an error I didn't create, and I just don't like it. Maybe if the product worked right I would like it, but right now I am not sure what to do.
Post the error and we will see.
__________________
hth
-nv

She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

When in doubt, read the FAQ.
Then ask a smart question.
nvoigt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 10:38 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22