Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28
  1. #11
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    Originally Posted by yung View Post
    Post the whole code at least, because these function aren't telling us where or how they're being called/used.

    Also you should add an "Else statement" because the code has nothing to return if you write a value too high.

    And you don't even have a function where the previous value is saved, it just gets replaced.

    You're using "ConvertToInt" which is useless because that only works if you input something like "3.14" it will output either 314 or 3 (rounded), I haven't used C# in a while

    Right now aantallabel is your textbox where the user can input a value that's anything within an int.

    So what did you do? You made textbox1 and user value output, but you did not make a function for the 2nd value that you want to use. Right now your code is literally saying "print in the users input, plus the textbox itself".
    There is no whole code(i've been stuck on this and i kept searching for an solution did not had time for the other things), i've put this apart to make it easy as possible. And YES i need a function to save the previous value i don't know what that function is, i thought it had something to do with loops. And float or double is "3.14" int is rounded.

    - - - Updated - - -

    This is the end result i need to get:
    I know how to do the rest, the only thing i don't know is [see thread]. That's all and because i know how to do i haven't worked on the other things only the design is completely done.

    Last edited by qais187; 10-16-2015 at 07:52 PM.


  2. #12
    Dave's Avatar 1' or 1=1--

    Join Date
    Aug 2008
    Country
    Posts
    24,017
    Thanked
    115
    Thanks
    12,958
    You will have to learn how to debug properly.
    Dump your variables to the console and see what's going wrong.

    It's hard to say what's going wrong by looking at the code you posted, but the while loop should never end because aantallabel (which is 0) will always be smaller than limiet.
    It's a terrible thing, I think, in life to wait until you're ready.
    I have this feeling now that actually no one is ever ready to do anything.
    There is almost no such thing as ready. There is only now.
    And you may as well do it now. Generally speaking, now is as good a time as any.

  3. #13
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    Originally Posted by Dave View Post
    You will have to learn how to debug properly.
    Dump your variables to the console and see what's going wrong.

    It's hard to say what's going wrong by looking at the code you posted, but the while loop should never end because aantallabel (which is 0) will always be smaller than limiet.
    I dont even know if my code is the right or the wrong one.. Thought the images were easy to understand. Well thanks anyways guys


  4. #14
    yung's Avatar ∅ ≠ S → ∅

    Join Date
    Jan 2011
    Country
    Posts
    834
    Thanked
    233
    Thanks
    118
    Originally Posted by qais187 View Post

    This is the end result i need to get:
    I know how to do the rest, the only thing i don't know is [see thread]. That's all and because i know how to do i haven't worked on the other things only the design is completely done.
    Dude that's way to complicated for you. It's way too early. If you want to store it or something you need to learn a little bit more, just do easy shit like this

    Code:
    public void button1_Click(object sender, RoutedEventArgs e){         
            int firstbox = Convert.ToInt32(textBox1.Text); //here you input first value
            int firstvalue = textBox1.Text; // this is to store the first value you write in textbox
            textBox1.Text=""; //this is so that the textbox clears after the click
    }
    
    
    public void button2_Click(object sender, RoutedEventArgs e){
            int secondbox = Convert.ToInt32(textBox1.Text);  //second input!
            int secondvalue = textBox.Text; //this is to store the second value that you input after buttonclick
            int result = firstvalue + secondvalue; //the sum
            int limitbox = Convert.ToInt32(textBox2.Text); //limit!
            if (result <= limitbox) { //if you only write < and the MAX is 20, it will give you Invalid because 20 is not less than 20
                textBox1.Text=result.tostring();
            }else{
                MessageBox.Show("Invalid input");
            }
    
    
    }
    This is horribly written and I don't even know C#, but you can use this kind of method, you need database knowledge like asp.net or something in order to store a value properly, or maybe something else. Either way I don't see the point of doing something that's way too hard while you barely know the basics, do simpler tasks instead of going for what looks easy but that you have no idea what functions are required.

    But for this program to work you need to make a button for Button1_Click that says "Add" or something, then another one for Button2_Click that says "Result" or something.
    Last edited by yung; 10-16-2015 at 09:32 PM.

  5. #15
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    Originally Posted by yung View Post
    Dude that's way to complicated for you. It's way too early. If you want to store it or something you need to learn a little bit more, just do easy shit like this

    Code:
    public void button1_Click(object sender, RoutedEventArgs e){         
            int firstbox = Convert.ToInt32(textBox1.Text); //here you input first value
            int firstvalue = textBox1.Text; // this is to store the first value you write in textbox
            textBox1.Text=""; //this is so that the textbox clears after the click
    }
    
    
    public void button2_Click(object sender, RoutedEventArgs e){
            int secondbox = Convert.ToInt32(textBox1.Text);  //second input!
            int secondvalue = textBox.Text; //this is to store the second value that you input after buttonclick
            int result = firstvalue + secondvalue; //the sum
            int limitbox = Convert.ToInt32(textBox2.Text); //limit!
            if (result <= limitbox) { //if you only write < and the MAX is 20, it will give you Invalid because 20 is not less than 20
                textBox1.Text=result.tostring();
            }else{
                MessageBox.Show("Invalid input");
            }
    
    
    }
    This is horribly written and I don't even know C#, but you can use this kind of method, you need database knowledge like asp.net or something in order to store a value properly, or maybe something else. Either way I don't see the point of doing something that's way too hard while you barely know the basics, do simpler tasks instead of going for what looks easy but that you have no idea what functions are required.

    But for this program to work you need to make a button for Button1_Click that says "Add" or something, then another one for Button2_Click that says "Result" or something.
    I get this(tried to put 'firstvalue' also by the 'button1_click1' but that didnt work :
    first error is: Cannot implicitly convert type 'string' to 'int'
    2nd: The name 'textBox' does not exist in the current context
    3rd: The name 'firstvalue' does not exist in the current context


    And yea i know but that's my homework we did not learn it how to do this little part of the homework is research on the internet.. the closest related thing to this is that we learnt to make a calculator.
    Last edited by qais187; 10-16-2015 at 10:09 PM.


  6. #16
    yung's Avatar ∅ ≠ S → ∅

    Join Date
    Jan 2011
    Country
    Posts
    834
    Thanked
    233
    Thanks
    118
    Well one problem is
    Code:
    int resultat = textBox1.Text; // It's supposd to say textBox1.Text that's a typo
    .
    But I can't use Visual Studio on Mac and I am too lazy to boot and build my top meme windows, so you have to debug/build/compile for me...

    But I don't think that works, so now I know that C# can't store two values in the same textbox unless it's saved in a txt file or some database asp.netshit I don't know, but it can at least not be put in a single function or anything-
    But you should do this...

    Remove all of int firstvalue and int secondvalue.

    Change
    Code:
    int result = firstvalue + secondvalue;
    to
    Code:
    int result = firstbox + secondbox;

  7. #17
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    Originally Posted by yung View Post
    Well one problem is
    Code:
    int resultat = textBox1.Text; // It's supposd to say textBox1.Text that's a typo
    .
    But I can't use Visual Studio on Mac and I am too lazy to boot and build my top meme windows, so you have to debug/build/compile for me...

    But I don't think that works, so now I know that C# can't store two values in the same textbox unless it's saved in a txt file or some database asp.netshit I don't know, but it can at least not be put in a single function or anything-
    But you should do this...

    Remove all of int firstvalue and int secondvalue.

    Change
    Code:
    int result = firstvalue + secondvalue;
    to
    Code:
    int result = firstbox + secondbox;
    There is only 2 textbox one for input the other for the limit, by saying 'secondvalue or secondbox' do you mean the label? Cause i tried but it doesn't make sense.. And i really appreciate that you do this ... if you don't want to reply anymore i'll understand it, its very frustrating ._.
    Last edited by qais187; 10-16-2015 at 10:29 PM.


  8. #18
    Banned

    Join Date
    Aug 2012
    Country
    Posts
    679
    Thanked
    394
    Thanks
    615
    Try 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.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
    
            private readonly int firstbox;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
    
            public void button1_Click(object sender, EventArgs e)
            {
                int firstbox = Int32.Parse( textBox1.Text ); //here you input first value
                int firstvalue = Int32.Parse( textBox1.Text ); // this is to store the first value you write in textbox
                textBox1.Text = ""; //this is so that the textbox clears after the click
            }
    
    
            public void button2_Click(object sender, EventArgs e)
            {
                int secondbox = Int32.Parse( textBox1.Text );  //second input!
                int secondvalue = Int32.Parse( textBox1.Text ); //this is to store the second value that you input after buttonclick
                int result = firstbox + secondbox; //the sum
                int limitbox = Int32.Parse( textBox2.Text ); //limit!
    
                if (result <= limitbox)
                { //if you only write < and the MAX is 20, it will give you Invalid because 20 is not less than 20
                    textBox1.Text = result.ToString();
                }
                else
                {
                    MessageBox.Show("Invalid input");
                }
    
    
            }
        }
    }
    I made firstbox an instance variable otherwise it would have been out of context.

    Remember to edit the namespace. You may also need to remove readonly.
    Last edited by Paul; 10-16-2015 at 10:52 PM.

  9. #19
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    Originally Posted by Paul View Post
    Try 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.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
    
            private readonly int firstbox;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
    
            public void button1_Click(object sender, EventArgs e)
            {
                int firstbox = Int32.Parse( textBox1.Text ); //here you input first value
                int firstvalue = Int32.Parse( textBox1.Text ); // this is to store the first value you write in textbox
                textBox1.Text = ""; //this is so that the textbox clears after the click
            }
    
    
            public void button2_Click(object sender, EventArgs e)
            {
                int secondbox = Int32.Parse( textBox1.Text );  //second input!
                int secondvalue = Int32.Parse( textBox1.Text ); //this is to store the second value that you input after buttonclick
                int result = firstbox + secondbox; //the sum
                int limitbox = Int32.Parse( textBox2.Text ); //limit!
    
                if (result <= limitbox)
                { //if you only write < and the MAX is 20, it will give you Invalid because 20 is not less than 20
                    textBox1.Text = result.ToString();
                }
                else
                {
                    MessageBox.Show("Invalid input");
                }
    
    
            }
        }
    }
    I made firstbox an instance variable otherwise it would have been out of context.

    Remember to edit the namespace. You may also need to remove readonly.
    It still says "The name 'firstbox' does not exist in the current context" im using xaml if its making a difference


  10. #20
    Banned

    Join Date
    Aug 2012
    Country
    Posts
    679
    Thanked
    394
    Thanks
    615
    Originally Posted by qais187 View Post
    It still says "The name 'firstbox' does not exist in the current context" im using xaml if its making a difference
    Oh, you're using WPF. Yes it does, make a difference. Thought you were using winforms.

    It shouldn't be out of context. I never receoeved that error in my debugger.

Page 2 of 3 FirstFirst 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)