none
numbers

    Question

  • Hi everyone. .hope you are fine. .
    I am working on a project with numbers using vs 2015, but I need little knowledge from your side.....
    in the form I have 2 Texboxes one Label for Output show and one Command
    for example if any user uses the application it should show answers like Roundoff to the below 100.

    if text box1 is 14565 and textbox 2 is 3566 answer is 18131 but it should display in Label as 18100.

    another example txt1 4578 and 578 answer 5156 but it should display in Label as 5100 

    Thanks

    Tuesday, March 8, 2016 1:47 PM

Answers

  • Here - I removed the code comments which were confusing you:

    string sTextBox1 = TextBox1.Text;
    string sTextBox2 = TextBox2.Text;
    int iSum = int.Parse(sTextBox1) + int.Parse(sTextBox2);
    string sLabel1 = (iSum - (iSum % 100)).ToString();
    Label1.Text = sLabel1;

    Best wishes, Davin Mickelson

    Thursday, March 10, 2016 2:54 PM
    Answerer
  • This is code that goes in the button1_Click() event handler method.

    • textBox1 is the name of the first textbox control on your form
    • textBox2 is the name of the second textbox control on your form
    • label1 is the name of the label control on your form
    • button1 is the name of the button on your form

    You can change the code below to use the same names as your controls on your form.

    Because of your use of "Dim", it looks like you are using Visual Basic (VB). My example was in C#. Here it is in VB:

        Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
            Dim sTextBox1 As String
            sTextBox1 = textBox1.Text
            Dim sTextBox2 As String
            sTextBox2 = textBox2.Text
            Dim iSum As Integer
            iSum = CInt(sTextBox1) + CInt(sTextBox2)
            Dim sLabel1 As String
            sLabel1 = (iSum - (iSum Mod 100)).ToString()
            label1.Text = sLabel1
        End Sub

    Good luck!

    Best wishes, Davin Mickelson

    Wednesday, March 16, 2016 4:09 PM
    Answerer

All replies

  • Hi, Rakcshithc.

    Here is some code that achieves that:

    string sTextBox1 = TextBox1.Text; // 1st textbox holds 4578
    string sTextBox2 = TextBox2.Text; // 2nd textbox holds 578
    int iSum = int.Parse(sTextBox1) + int.Parse(sTextBox2);
    string sLabel1 = (iSum - (iSum % 100)).ToString(); // sLabel1 set to 5100
    Label1.Text = sLabel1;

    Good luck!


    Best wishes, Davin Mickelson

    Wednesday, March 9, 2016 4:16 PM
    Answerer
  • thank you sir for your reply...

    but the above code holds only specified number 4578 and 578 = 5100.. if a user inputs different number in textboxes how its shows n label? that means user is free to input any number on textboxes is  it works??

    i.e answer should round of to the preceding 100.

    Examples: 5478 = 5400, 6897= 6800, 14578= 14500 like this

    Thursday, March 10, 2016 7:49 AM
  • Here - I removed the code comments which were confusing you:

    string sTextBox1 = TextBox1.Text;
    string sTextBox2 = TextBox2.Text;
    int iSum = int.Parse(sTextBox1) + int.Parse(sTextBox2);
    string sLabel1 = (iSum - (iSum % 100)).ToString();
    Label1.Text = sLabel1;

    Best wishes, Davin Mickelson

    Thursday, March 10, 2016 2:54 PM
    Answerer
  • Sir this code is fully confusion. .. can you explain me what is the command.. 

    Dim.....?

    Dim....?

    The same code I used in project its error..

    Wednesday, March 16, 2016 3:40 PM
  • string sTextBox1 = TextBox1.Text;
    string sTextBox2 = TextBox2.Text;
    int iSum = int.Parse(sTextBox1) + int.Parse(sTextBox2);
    string sLabel1 = (iSum - (iSum % 100)).ToString();

    Label1.Text = sLabel1;

    What is sTextbox1,, sTextbox2,, iSum??

    Can you give me full code

    Wednesday, March 16, 2016 3:43 PM
  • This is code that goes in the button1_Click() event handler method.

    • textBox1 is the name of the first textbox control on your form
    • textBox2 is the name of the second textbox control on your form
    • label1 is the name of the label control on your form
    • button1 is the name of the button on your form

    You can change the code below to use the same names as your controls on your form.

    Because of your use of "Dim", it looks like you are using Visual Basic (VB). My example was in C#. Here it is in VB:

        Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
            Dim sTextBox1 As String
            sTextBox1 = textBox1.Text
            Dim sTextBox2 As String
            sTextBox2 = textBox2.Text
            Dim iSum As Integer
            iSum = CInt(sTextBox1) + CInt(sTextBox2)
            Dim sLabel1 As String
            sLabel1 = (iSum - (iSum Mod 100)).ToString()
            label1.Text = sLabel1
        End Sub

    Good luck!

    Best wishes, Davin Mickelson

    Wednesday, March 16, 2016 4:09 PM
    Answerer
  • Alright. .. it fully works thank you so much...
    Thursday, March 17, 2016 2:50 AM