Adding spinners together into a text box

  • I have five spinner contols that I want to add together into a text box.


    As of now, the answer is being read as text, not values. How do I convert them to values so a sum will appear?


    What I have:


    Spinner 1.value = 1
    Spinner2.value = 2
    spinner3. value = 3
    Spinner4.value = 4
    Spinner5.value = 5


    Txt1.value = 12345


    What I want is:


    Txt1.value = 15


    thanks

  • The spinner value returns text, so convert it to a number useing the VAL function. Your text box would then be assigned the value of val(spinner1.value)+val(spinner2.value))+val(spinner3.value))+val(spinner4.value))+val(spinner5.value)

  • Thanks,


    This is what I initially did but it was still read as text.


    Should I convert the text box to a value using another variable?

  • Yes, the textbox holds just text, so if you are taking something from it that you want to use as a number you need to run it through the VAL function (in VBA; in a worksheet, the function is called VALUE).

  • Thank you


    I am still getting an error and I wonder if it is because I have the sum formula in each one of the Spinner Change Event.


    Would this have any effect on the output?

  • What sort of error? Is each spinner change event adding up all of the spinner values and putting the total in a text box? Perhaps you could attach an example of what you are trying to do.

  • Attached is the file with a userform.


    The userform column that is being added is column 2 - the spinners with the MegaStar heading.


    When you increase a spinner, the code fails.


    Why


    thanks

  • The failure I got with the first spinner was caused at the code line
    txttotalhopcnt.Value = CLng(txtmicrostarcnt.Value) + CLng(Txtmegastar1ncnt.Value) + _
    CLng(txtconstellationcnt.Value) + CLng(txtauroracnt.Value) + CLng(txt155count.Value)


    The problem is most of those values are not numbers and can't be converted. At least one was empty, another had real text. Before converting, I guess you will have to go through them one at a time and see which are numeric. or try adding them a step at a time with a resume next to skip the ones that can't be handled.

  • Thanks Derek


    I was experimenting with this. I copied and pasted this same code into one of textbox events (it had previously been in the Spinner Change event).


    You know, it added properly. Next question, how do I get the text box to update automatically whenever one of the spinners is updated?


    Thanks

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!