8 Replies - 2825 Views - Last Post: 23 January 2011 - 05:28 PM Rate Topic: -----

#1 Guest_Andrew*


Reputation:

Multiplying in textbox

Posted 23 January 2011 - 12:20 PM

Hi i have a question i have two textboxs with data in them and i would like to multiply the to textboxs but it dosent work this is what i have so far can some one help?

        Random num1 = new Random();
        int a;
        int b;
        int i;
        


        public Form1()
        {
            InitializeComponent();
        }


        private void random()
        {

            a = num1.Next(1, 100);
            b = num1.Next(1, 100);

            textBox1.Text = ("" + a);
            textBox2.Text = ("" + B)/>;

        }

        private void check()
        { 
        
        if (textBox3.Text == a * B)/>
        
        {
        
        }



Is This A Good Question/Topic? 0

Replies To: Multiplying in textbox

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Multiplying in textbox

Posted 23 January 2011 - 12:39 PM

I really couldnt even call this a valid attempt. I mean, really what is this supposed to be doing, because it's not at all what you describe as your goal. A *good faith effort* means you actually make an effort to write the code. This is just some gibberish in an effort to get someone to feel sorry for you and do your homework for you.

Please describe what you *think* is happening here. You have methods you never call. You obviously never tried so much as putting in a breakpoint and walking through this.

Debugging tutorial





I agree we are happy to help. Sometimes the best help is examples. Sometimes its solving the problem. Sometimes its pointing toward some good resources.

I am going to guess that you are trying to teach yourself C# without much guidance, a decent book or without knowing where to look. Sometimes just knowing where to look can make all the difference. Google is your friend.
Search with either "C#" or "MSDN" as the first word: "MSDN Picturebox", "C# Custom Events", "MSDN timer" etc.

But honestly, just typing away and seeing what pops up in Intellisense is going to make your self-education take 20 years. You can learn by trying to reverse engineer the language through banging on the keyboard - or you can learn by doing the tutorials and following a good "How to learn C#" book.

May I suggest picking up a basic C# introductory book? It's not that people here don't want to be helpful, but there is a certain amount of basic learning work that one should really take upon themselves before asking for help. There are so many great "How do I build my first application" tutorials on the web... There are dozens of "Learn C# in 21 days", "My first C# program" books at your local book seller or even public library... Asking a forum, any forum, to hand-hold you through it is just redundant. In many ways it disrespects the people who have invested dozens of hours in the on-line tutorials and those that spent thousands of hours in authoring books. C# resources. Start here

Build a Program Now! in Visual C# by Microsoft Press, ISBN 0-7356-2542-5
is a terrific book that has you build a Windows Forms application, a WPF app, a database application, your own web browser.

C# Cookbooks
Are a great place to get good code, broken down by need, written by coding professionals. You can use the code as-is, but take the time to actually study it. These professionals write in a certain style for a reason developed by years of experience and heartache.

Microsoft Visual Studio Tips, 251 ways to improve your productivity, Microsoft press, ISBN 0-7356-2640-5
Has many, many great, real-world tips that I use all the time.

The tutorials below walk through making an application including inheritance, custom events and custom controls.
Quick and easy custom events
Bulding an application - Part 1
Building an application - Part 2
Debugging tutorial
Working with environmental variables

Writing a text file is always one of the first things people want to do, in order to store data like high-scores, preferences and so on
Writing a text file tutorial.

These are just good every-day references to put in your bookmarks.
MSDN C# Developers Center with tutorials
Welcome to Visual Studio

Have you seen the MSDN Code Samples? They spent a lot of time creating samples and demos. It seems a shame to not use them.

  • Anonymous Delegates: Demonstrates the use of unnamed delegates to reduce application complexity.
  • Arrays: Shows how to use arrays.
  • Attributes: Shows how to create custom attribute classes, use them in code, and query them through reflection.
  • Collection Classes: Shows how to make non-generic collection classes that can be used with the foreach statement.
  • COM Interop Part I: Shows how to use C# to interoperate with COM objects.
  • COM Interop Part II: Shows how to a use a C# server together with a C++ COM client.
  • Commandline: Demonstrates simple command-line processing and array indexing.
  • Condiational Methods: Demonstrates conditional methods, which provide a powerful mechanism by which calls to methods can be included or omitted depending on whether a symbol is defined.
  • Delegates: Shows how delegates are declared, mapped to static and instance methods, and combined into multicast delegates.
  • Events: Shows how to declare, invoke, and configure events in C#.
  • Explicit Interface: Demonstrates how to explicitly implement interface members and how to access those members from interface instances.
  • Generics: Shows how to make generic collection classes that can be used with the foreach statement.
  • Hello World: A Hello World application.
  • Indexers Part I: Shows how C# classes can declare indexers to provide array-like access to objects.
  • Indexers Part II: Shows how to implement a class that uses indexed properties. Indexed properties enable you to use a class that represents an array-like collection.
  • Libraries: Shows how to use compiler options to create a DLL from multiple source files; also, how to use the library in other programs
  • Named and Optional (C# 4.0): Demonstrates Named and Optional parameters, an alternative to method overloads
  • Nullable: Demonstrates value types, such as double and bool, that can be set to null
  • Office Sample (C# 4.0): Demonstrates how Dynamic and COM Interop make it easy to call Microsoft Office in C# 4.0
  • OLEDB: Demonstrates how to use a Microsoft Access database from C# by creating a dataset and adding tables to it.
  • Operator Overloading: Shows how user-defined classes can overload operators
  • Partial Types: Demonstrates how classes and structures can be defined in multiple C# source-code files
  • PInvoke: Shows how to call exported DLL functions from C#
  • Properties: Shows how properties are declared and used; also demonstrates abstract properties
  • Python Sample (C# 4.0): Learn how to call a Python script by using the Dynamic feature in C# 4.0
  • Security: Discusses .NET Framework security and shows how to modify security permissions in C# by using permission classes and permission attributes
  • Simple Variance (C# 4.0): See how Covariance and Contravariance are supported in generic interfaces and delegates
  • Structs: Shows how to use structs in C#.
  • Threading: Demonstrates various thread activities such as creating and executing a thread, synchronizing threads, interacting between threads, and using a thread pool
  • Unsafe: Shows how to use unmanaged code (code that uses pointers) in C#
  • User Conversions: Shows how to define conversions to and from user-defined types
  • Versioning: Demonstrates versioning in C# by using the override and new keywords
  • XML Documents: Shows how to document code by using XML
  • Yield: Demonstrates how to use the yield keyword to filter items in a collection

Was This Post Helpful? 1
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: Multiplying in textbox

Posted 23 January 2011 - 12:42 PM

You have to watch what data types you are using when you compare. You can't simply multiply two integers together and then compare that to a textbox value because the textbox.text value returns a string. It would be like saying what is "hello == 13". Doesn't make sense. So, we need to make them the same type. We can do this by converting the integer to a string and compare the strings.

// Multiply a and b, convert to a string and store it in "sum" for comparison
String sum = (a * B)/>.ToString();

if (textBox3.Text == sum) {
   // Code here if textbox3 has the same value as the values in textbox1 and textbox2
}



Apply this principle to setting your other textBox1 and 2....

textBox1.Text = a.ToString();



You never want to simply tack on "" to make it a string. Try that out and let us know how it goes. Post any error messages you are getting.

:)
Was This Post Helpful? 0
  • +
  • -

#4 adgarci  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 96
  • Joined: 26-August 09

Re: Multiplying in textbox

Posted 23 January 2011 - 12:43 PM

a and b both need to be converted to strings before you can display them in a text box using a.ToString()
If you want to compare whatever is in textBox3 with integers, it must first be parsed.
private void check() 
{ 
      int textBox3ContentIntForm = Int32.Parse(textBox3.Text);
      if (textBox3ContentIntForm == (a * B)/>)
      {//do something}
}



Edit: *sigh* I took too long because I had to make a test to be sure I knew what I was saying.... Oh well

This post has been edited by adgarci: 23 January 2011 - 12:45 PM

Was This Post Helpful? 0
  • +
  • -

#5 Guest_Andrew*


Reputation:

Re: Multiplying in textbox

Posted 23 January 2011 - 12:44 PM

no offence guys that was kind of rude i am very new to coding and i wanted a little guidance and i did find out the problem it was very simple as to textBox3.Text = (a*B).ToString() but still i think that was unnecessary!
Was This Post Helpful? 0

#6 Guest_Andrew*


Reputation:

Re: Multiplying in textbox

Posted 23 January 2011 - 12:47 PM

View Postadgarci, on 23 January 2011 - 12:43 PM, said:

a and b both need to be converted to strings before you can display them in a text box using a.ToString()
If you want to compare whatever is in textBox3 with integers, it must first be parsed.
private void check() 
{ 
      int textBox3ContentIntForm = Int32.Parse(textBox3.Text);
      if (textBox3ContentIntForm == (a * B)/>)
      {//do something}
}



Edit: *sigh* I took too long because I had to make a test to be sure I knew what I was saying.... Oh well

i appreciated your help very much unlike the first post :)
Was This Post Helpful? 0

#7 adgarci  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 96
  • Joined: 26-August 09

Re: Multiplying in textbox

Posted 23 January 2011 - 12:50 PM

View PostAndrew, on 23 January 2011 - 12:44 PM, said:

no offence guys that was kind of rude i am very new to coding and i wanted a little guidance


To be honest, the answers they gave are far better because they gave resources to actually learn to program and become better, I just gave a quick answer because I have done this so many times before
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Multiplying in textbox

Posted 23 January 2011 - 12:53 PM

View PostAndrew, on 23 January 2011 - 12:44 PM, said:

no offence guys that was kind of rude i am very new to coding and i wanted a little guidance and i did find out the problem it was very simple as to textBox3.Text = (a*B).ToString() but still i think that was unnecessary!


I'm kinda the designated frank-speaking jerk around here. I'm not blind to that. I don't have an issue with that. It's the place of your parents and your priest to coddle you and tell you that you can do anything. I honestly think that type of ego stroking does more harm than good after about age 12. I'm one of the guys that are going to tell you the blunt truth in the recognition that few people do in this world - But with the hopes that if someone speaks to you like an adult that maybe you'll rise to occasion.

Looking at your code it sure looks like you have not even tried to work through a series of intro to C# tutorials. You haven't so much as picked up a "C# in 21 days" book. You're just banging on a keyboard trying to figure out how this whole coding thing works. Honestly all that is going to do is frustrate the crap out of you and you'll walk away from it. So I gave you a BUNCH of book references, on-line resources and links to learn from, and maybe a little emotional impact to help motivate you. You can either avail yourself of them and take it upon yourself to learn the right way... or you can cry about how mean I was talking to you like a grown up. It's your call.

This post has been edited by tlhIn'toq: 23 January 2011 - 01:01 PM

Was This Post Helpful? 1
  • +
  • -

#9 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: Multiplying in textbox

Posted 23 January 2011 - 05:28 PM

View PostAndrew, on 23 January 2011 - 11:44 AM, said:

no offence guys that was kind of rude i am very new to coding and i wanted a little guidance and i did find out the problem it was very simple as to textBox3.Text = (a*B).ToString() but still i think that was unnecessary!



Ummm... I was being very courteous and told you exactly what the problem was. Did you not see my smiley and helpful comment saying to try it out and post the error messages if you still get them?

I wasn't voted DIC's 2009 and 2010's nicest member for nothing! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1