Page 1 of 3 123 LastLast
Results 1 to 10 of 28
  1. #1
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    If i type 6 into the textbox and click on the button, the label will turn into 6(so far good). But when i want to add 4 to the 6 it doesn't change to 10.

    Can someone tell me what i'm doing wrong here? I've looked the net for many hours without luck.
    Code:
    private void button_Click(object sender, RoutedEventArgs e)
            {
    
                int aantaltextBox = Convert.ToInt32(textBox.Text);
                int limiet = Convert.ToInt32(textBox1.Text);
                int aantallabel = Convert.ToInt32(label.Content=0);
                while (aantallabel < limiet)
                {
                    label.Content = aantallabel + aantaltextBox;
                }    
            }
    'Max'(limiet) means the label cant go over 20.




  2. #2
    God

    Join Date
    Jul 2013
    Country
    Posts
    243
    Thanked
    107
    Thanks
    101
    this looks so broken, can't even see it.


    ps: dave can easily solve this for u

  3. The following user said thank you to Sex for this useful post:

    qais187 (10-16-2015)

  4. #3
    Banned

    Join Date
    Aug 2012
    Country
    Posts
    679
    Thanked
    394
    Thanks
    615
    Why are you converting a value to integer? You inputting the value into an integer variable.

  5. #4
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    Originally Posted by Paul View Post
    Why are you converting a value to integer? You inputting the value into an integer variable.
    Thats why im posting it here, i only can do what i learnt.. as you can guess i am a beginner in this.


  6. #5
    Resort's Avatar Aloha

    Join Date
    May 2011
    Country
    Posts
    3,449
    Thanked
    1,769
    Thanks
    1,235
    Probably easier to understand and make it work if you just have two separate textboxes for the values that you want to add together. Then you can just add textBox1.text + textBox2.Text and display it in the label.

    Unless you have to do it the way you're doing.
    Last edited by Resort; 10-16-2015 at 07:15 PM.

  7. #6
    Banned

    Join Date
    Aug 2012
    Country
    Posts
    679
    Thanked
    394
    Thanks
    615
    Post more than just that function. That function should be working fine, only thing that was wrong with it is that you're converting to int when you're assigning it to int.

  8. #7
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    Originally Posted by Resort View Post
    Probably easier to understand and make it work if you just have two separate textboxes for the values that you want to add together. Then you can just add textBox1.text + textBox2.Text and display it in the label.

    Unless you have to do it the way you're doing.
    Yea i know that would be easy.. what i'm trying to do is replacing textBox2 with a label.

    - - - Updated - - -

    Originally Posted by Paul View Post
    Post more than just that function. That function should be working fine, only thing that was wrong with it is that you're converting to int when you're assigning it to int.
    I don't get what you saying about the 'int' can you please explain with a example?


  9. #8
    Banned

    Join Date
    Aug 2012
    Country
    Posts
    679
    Thanked
    394
    Thanks
    615
    Code:
    private void button_Click(object sender, RoutedEventArgs e)
            {
    
                int aantaltextBox = textBox.Text;
                int limiet = textBox1.Text;
                int aantallabel = label.Content=0;
                while (aantallabel < limiet)
                {
                    label.Content = aantallabel + aantaltextBox;
                }
    If both text boxes contain a number, there is no need to convert to integer because it has assigned itself as an int (or so it should be). You are also assigning it to an int variable.

  10. #9
    yung's Avatar ∅ ≠ S → ∅

    Join Date
    Jan 2011
    Country
    Posts
    834
    Thanked
    233
    Thanks
    118
    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. But even with that you're using "int" at the beginning so that makes even less sense to use "ConvertToInt"

    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".
    Last edited by yung; 10-16-2015 at 07:40 PM.

  11. #10
    qais187's Avatar Junior Member

    Join Date
    Nov 2014
    Country
    Posts
    93
    Thanked
    110
    Thanks
    15
    Originally Posted by Paul View Post
    Code:
    private void button_Click(object sender, RoutedEventArgs e)
            {
    
                int aantaltextBox = textBox.Text;
                int limiet = textBox1.Text;
                int aantallabel = label.Content=0;
                while (aantallabel < limiet)
                {
                    label.Content = aantallabel + aantaltextBox;
                }
    If both text boxes contain a number, there is no need to convert to integer because it has assigned itself as an int (or so it should be). You are also assigning it to an int variable.
    [nvm, now i have to use just other name thanks for the tip] No it doesn't work.. if you do for example textbox 1(40) + textbox 2(50)= 4050(you get this because its a string) you still need to convert.
    Last edited by qais187; 10-16-2015 at 07:43 PM.


Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

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