I have assigned the value whether the check box is ticked or not to a vairable.I want to pass the value to a function.

how do I do that ?

if (checkbox1.checked==true)
value1 = "I am here"
if (checkbox2.checked==true)
value2="I am there"

value3 = value1 + value2

function (value3)

thee b problem is value 1 and value 2 are out of scope for value 3 ?what should I do ?

Recommended Answers

All 2 Replies

Declare the variables value1 and value2 before the if-statements.

int value1 = 0;
int value2 = 0;
if (checkbox1.checked) // you don't need to say == true here
  value1 = 1000000;
if (checkbox2.checked)
  value2 = -392014;
int value3 = value1 + value2;


public void myFunction(int value3)
  // do something...

PS please use code tags, it makes posts much easier to read.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.