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.
Pages: 1
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
You're trying to access a variable that is outside of the current scope.
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
thanks for helping me :):):):):):):)
Last edited by MortenJeppe (Aug 11 2012 6:47:46 am)
I don't know much about C#, but i know some C, C++ and VB. But good luck with whatever you are making.
thank ^ (im trying to make a game)
Is it a game about pressing two buttons that does exactly the same thing?
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
Is it a game about pressing two buttons that does exactly the same thing?
no it was just an example XD
Is this bot related?
Player Since 2011. I used to make bots and stuff.
Offline
Is this bot related?
no why?
Pages: 1
[ Started around 1738775316.1151 - Generated in 0.047 seconds, 13 queries executed - Memory usage: 1.47 MiB (Peak: 1.59 MiB) ]