Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 Before February 2015

MortenJeppe
Guest

help me c#

i have problems with variables (im new in c#)

what is there wrong with this code?

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;  namespace eeforum {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }          private void button1_Click(object sender, EventArgs e)         {             int v = 1;             v = v + 1; //this work         }          private void button2_Click(object sender, EventArgs e)         {             v = v + 1;     //but not this.  how do i this??         }     } }

plz help me

#2 Before February 2015

Watashii
Guest

Re: help me c#

You're trying to access a variable that is outside of the current scope.

#3 Before February 2015

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,658

Re: help me c#

I fixed the code

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;  namespace eeforum {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }         int v=1; //to work in all program should be here         private void button1_Click(object sender, EventArgs e)         {            v++;         }          private void button2_Click(object sender, EventArgs e)         {             v++;         }     } } //if I press both buttons once result will be v=3;

or

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;  namespace eeforum {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }         private void button1_Click(object sender, EventArgs e)         {            int=1 //to work only here            v++;         }          private void button2_Click(object sender, EventArgs e)         {             int=1 //to work only here             v++;         }     } } //if you press buttons results always be the same v=2;


Everybody edits, but some edit more than others

Offline

#4 Before February 2015

MortenJeppe
Guest

Re: help me c#

thanks for helping me   //forums.everybodyedits.com/img/smilies/smile:):):):):):):)

Last edited by MortenJeppe (Aug 11 2012 6:47:46 am)

#5 Before February 2015

soccerfreak006
Guest

Re: help me c#

I don't know much about C#, but i know some C, C++ and VB. But good luck with whatever you are making.

#6 Before February 2015

MortenJeppe
Guest

Re: help me c#

thank ^   (im trying to make a game)

#7 Before February 2015

Watashii
Guest

Re: help me c#

Is it a game about pressing two buttons that does exactly the same thing?

#8 Before February 2015

Tako
Member
From: Memphis, Tennessee, USA
Joined: 2015-08-10
Posts: 6,663
Website

Re: help me c#

Watashii wrote:

Is it a game about pressing two buttons that does exactly the same thing?

Everyone has their own genre!

Kidding; he's probably working out basic GUI. There are a million uses for a button that adds one to the total.

Also, like Zumza said, I'd use `v++;`. Much simpler.


Yeah, well, you know that's just like, uh, your opinion, man.

Offline

#9 Before February 2015

MortenJeppe
Guest

Re: help me c#

Watashii wrote:

Is it a game about pressing two buttons that does exactly the same thing?

no it was just an example XD

#10 Before February 2015

Cyral
Member
From: United States
Joined: 2015-02-15
Posts: 2,269

Re: help me c#

Is this bot related?


Player Since 2011. I used to make bots and stuff.

Offline

#11 Before February 2015

MortenJeppe
Guest

Re: help me c#

EE Beast wrote:

Is this bot related?

no why?

MortenJeppe 1423665296296136

Board footer

Powered by FluxBB

[ Started around 1738773884.2736 - Generated in 0.046 seconds, 14 queries executed - Memory usage: 1.47 MiB (Peak: 1.6 MiB) ]