Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C#- calling method to get data from textbox and display in messagebox


  • Please log in to reply
6 replies to this topic

#1 donbrooks

donbrooks

  • Members
  • 5 posts
  • OFFLINE
  •  
  • Local time:03:53 PM

Posted 25 June 2009 - 05:00 AM

Hello,
I am calling a method to display data in a messagebox- unforutunetly - I am just trying to learn override and calling method to use in interface - so my code not working:
class MyBaseClass
{
public static int _num1;
public static int _num2;

public int Num1
{
get
{
return _num1;
}
set
{
_num1 = value;
}
}
public int Num2
{
get
{
return _num2;
}
set
{
_num2 = value;
}
}
public virtual int calculate()
{
return _num1 + _num2;
}
}
}

class myDerivedClass: MyBaseClass
{
private int _num1;
private int _num2;

public override int calculate()
{
return _num1 * _num2;
}
}
private void button3_Click(object sender, EventArgs e)
{
I havemyDerivedClass mdc = new myDerivedClass();

mdc.Num1 = int.Parse(textBox1.Text);
mdc.Num2 = int.Parse(textBox2.Text);

MessageBox.Show(total.ToString()); two textboxes on form and a button- am attempting to code button to display results from data entered in textboxes

I actually want to use first calculate method to get addition result and then override to get multiplication
thank you

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:53 PM

Posted 25 June 2009 - 07:31 AM

Define 'not working'.

#3 donbrooks

donbrooks
  • Topic Starter

  • Members
  • 5 posts
  • OFFLINE
  •  
  • Local time:03:53 PM

Posted 25 June 2009 - 11:22 AM

definition of not working: (sorry)
I am am a newbie to overriding and overloading- this is overriding a method.
I created these two classes - so I could override the method calculate in the mybaseclass.
but cannot call the method to calculate to add numbers together
cannot call the override method to change to multiply numbers.

what I am totally uninformed on is how to call the methods and have _num1 and _num2 values connect to textbox1 and textbox2 -looking for help beyond myDerivedClass mdc = new myDerivedClass()
thank y ou

Edited by donbrooks, 25 June 2009 - 11:24 AM.


#4 donbrooks

donbrooks
  • Topic Starter

  • Members
  • 5 posts
  • OFFLINE
  •  
  • Local time:03:53 PM

Posted 25 June 2009 - 11:57 AM

maybe more precise- I cannot call the calculate method above to total the numbers in text boxes on form to display in messagebox- can you help at all?

#5 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:53 PM

Posted 25 June 2009 - 12:25 PM

Yes, I can help; just not right now. Working on my own problems at the moment. :thumbsup:

#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:02:53 PM

Posted 25 June 2009 - 06:20 PM

Just two things; it would be helpful if you used the code formatting tags so that I can actually see what your code looks like, and if there is something as simple as a typo. For instance, I can't tell if this: I havemyDerivedClass mdc = new myDerivedClass(); is an actual line in your code, or if it is just a formatting error from when you made the post. I can't actually see that the listener is properly enclosed either. In short, I can't tell if you even have proper code.

#7 donbrooks

donbrooks
  • Topic Starter

  • Members
  • 5 posts
  • OFFLINE
  •  
  • Local time:03:53 PM

Posted 25 June 2009 - 07:15 PM

Thanks- sorry for muddled code
I have been struggling with creating a object-setting properties-calling methods and displaying total
now in that order I have made buttons work-
my derived class add = new myDerived Class()
add.num1 = Int32.Parse(textbox1.text);
add.num2 = Int32.Parse(textbox2.text);
int mulitply = add.calculate();
messagebox .....

next time I'll post actual code and try to explain less and clearer




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users