Forum Discussion
Abhinav Gupta
Sep 02, 2018Copper Contributor
Display the Sum(on click) of ones in the four variables(label) -- one variable is string
Hello sir, I have a small problem set here attached the project and code. I am taking answers in the form of YES, NO and NA in the combo drop down. Based on these selections, I am storing val...
- Sep 03, 2018
You will need to do two things, (1) Catch the errors so that the NA doesn't kill your code, (2) convert the captions in your labels to integer.
Give this code a try in your CommandButton1:
Private Sub CommandButton1_Click()'Added labels 1 to 4 to hold the captions from your lbls as integersDim Total As Integer
Dim label1 As Integer
Dim label2 As Integer
Dim label3 As Integer
Dim label4 As Integer'Catches any errors and resumes the codeOn Error Resume Next'Converts your captions (text) into integer (numbers) so it can be summedlabel1 = lbl1.Caption
label2 = lbl2.Caption
label3 = lbl3.Caption
label4 = lbl4.Caption'Sum the valuesTotal = label1 + label2 + label3 + label4'Output result
totalqs.Caption = TotalI have added your file with the working code for you to try.
Hope that makes sense and helps!
Cheers
Damien
Abhinav Gupta
Sep 02, 2018Copper Contributor
Please anyone help.