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 03, 2018Copper Contributor
Hi Damien,
Thank for your reply and educating me about the importance of data type and catching errors. That really helped me a lot.
Is there any workaround to Count the Non "NA" value mean count 1 & 0 in the above four variables say? I need to make calculations based on these data to make a ratio.
Thank for your reply and educating me about the importance of data type and catching errors. That really helped me a lot.
Is there any workaround to Count the Non "NA" value mean count 1 & 0 in the above four variables say? I need to make calculations based on these data to make a ratio.
Damien_Rosario
Sep 05, 2018Silver Contributor
Hi Abhinav
Can you give me an example please?
Cheers
Damien
- Abhinav GuptaSep 05, 2018Copper ContributorHi Damien,
Here is an example,
Four Question- Four Answers.
An answer can be YES, NO or NA.
Score = Number of Yes/(Total Number of YES + Total Number of NO)(Excluding all NA option).
So we do not want to count the NA while doing these calculations.
Does that make sense?
Thanks
Abhinav- Abhinav GuptaSep 12, 2018Copper ContributorHi Damien,
Hope you are doing good!
I think I figured out the solutions myself. Thank you for the help.
Cheers
Abhinav- Damien_RosarioSep 13, 2018Silver Contributor
Sorry I didn't get back to you in time. Have been flat out with running training for go-live of our new financial system next week at work!
Glad you have resolved the question my friend. The fun part of programming is playing around and trying different things to see what works and what doesn't.
Keep up the good work and see you out there!
Cheers
Damien