# [RESOLVED] How to calculate the total sum of the numbers

Show 50 post(s) from this thread on one page
Page 1 of 2 12 Last
• October 3rd, 2012, 02:19 PM
Halosar7
[RESOLVED] How to calculate the total sum of the numbers
Hi guys, i need your help. I am beginner on this vb6 so i hope you can help me.

In Vb6 i create 1 Command button, 1 Label and 8 TextBox.

In Command button i wrote this code:

Command1_Click()

Label1 = Val(Text1) + Val(Text2) + Val(Text3) + Val(Text4) + Val(Text5) + Val(Text6) + Val(Text7) + Val(Text8)

In 8 TextBox for example i write date of birth: 1989 06 28 and then click command button. Then in label i see result 43. Now i need the number of 43 sum. ( 4 + 3 = 7).And if lets say number is 93 then 9 + 3 = 12 = 1 + 2 = 3.

I guess in vb6 code need write with If, Then, Else, End If arguments. For example:
If Label1 > 10 Then
Val(Text1) + Val(Text2)....
Else
EndIf
End sub

• October 3rd, 2012, 02:39 PM
dglienna
Re: How to calculate the total sum of the numbers
Hard to say with your sample.

#1 VB6 can calculate DATE() for you.
#2 Strings can use INSTR() to find a position from within a string
• October 3rd, 2012, 03:35 PM
Halosar7
Re: How to calculate the total sum of the numbers
How to calculate date which could indicate your age i know that.
With Strings (INSTR) i do not unfamiliar with that. If they can solve my problem then say code.

Can you know other methods to calculate calculate the total sum of the numbers
• October 3rd, 2012, 07:27 PM
DataMiser
Re: How to calculate the total sum of the numbers
So what you are trying to do is a numerology calcultaion?
• October 3rd, 2012, 10:30 PM
Eri523
Re: How to calculate the total sum of the numbers
Hmmm... This calculation looks somewhat familiar... :)

Here's a VBA function (used as a worksheet function) from one of my older Excel files, somewhat related to tarot cards:

Code:

```Function rqs(x, maxqs)     Dim TempX As Integer, TempQS As Integer         TempX = x     Do         TempQS = 0         Do             TempQS = TempQS + TempX Mod 10             TempX = Int(TempX / 10)         Loop While TempX > 0         TempX = TempQS     Loop While TempQS > maxqs     rqs = TempQS End Function```
The "r" in the function name means "recursive" and the "qs" means "Quersumme", the german translation of "digit sum". As the first parameter, the function takes the number of which to calculate the digit sum. In your example that would be 19890628 (as a number!). The second parameter determines the termination condition: The function keeps calculating the digit sum of the result it gets until that result is no bigger than the second parameter. In your example you'd pass 9 for that. (Warning: Passing a value smaller than 9 for that parameter is likely to result in an endless loop.)

This rather aged example of my VBA programming skills probably has some room for improvement. I posted it as-is, just to give you something to play with... :)
• October 3rd, 2012, 10:31 PM
Eri523
Re: How to calculate the total sum of the numbers
Quote:

Originally Posted by DataMiser
So what you are trying to do is a numerology calcultaion?

Yeah, looks like that... :D
• October 4th, 2012, 09:42 AM
Halosar7
Re: How to calculate the total sum of the numbers
Yes i trying to do numerology calculation.

This code is not working.

Code:

``` Function rqs(x, maxqs)     Dim TempX As Integer, TempQS As Integer         TempX = x     Do         TempQS = 0         Do             TempQS = TempQS + TempX Mod 10             TempX = Int(TempX / 10)         Loop While TempX > 0         TempX = TempQS     Loop While TempQS > maxqs     rqs = TempQS End Function```
You say that "Here's a VBA function (used as a worksheet function) from one of my older Excel files" I need for visual basic, not for excel.

Attachment 30411

Attachment 30413

I put two pictures.
In first pic. you see 1 label,1 command button and 8 TextBox.
In second pic. you see my code.

So can you do write code according to my example involving those files (label, command button and textbox)
• October 4th, 2012, 12:03 PM
dglienna
Re: How to calculate the total sum of the numbers
+ is the wrong way to CONCATENATE a string anyways. USE '&' instead!

Try making 3 Temporary labels first!
• October 4th, 2012, 01:30 PM
Halosar7
Re: How to calculate the total sum of the numbers
Why i need 3 labels? Identify all 3 labels function code and how i must use them.
• October 4th, 2012, 07:37 PM
DataMiser
Re: How to calculate the total sum of the numbers
I would try to help but I know little about numerology and can't quite make out what you are trying to do based on what is in your post. If you provide more detail then perhaps I could help.
• October 4th, 2012, 09:19 PM
jggtz
Re: How to calculate the total sum of the numbers
Code:

```    Dim intTotal1 As Integer     Dim strTotal1 As String     Dim intTotal2 As Integer         intTotal1 = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) + Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text) + Val(Text7.Text) + Val(Text8.Text)         strTotal1 = Format(intTotal1)     intTotal2 = Val(Left(strTotal1, 1)) + Val(Right(strTotal1, 1))     Label1.Caption = Format(intTotal2)```
It would be better if you validate that every textbox has an integer number inside (0 to 9)
Also validate that the first result (intTotal1 in this example) has 2 places
• October 4th, 2012, 09:59 PM
dglienna
Re: How to calculate the total sum of the numbers
Quote:

In 8 TextBox for example i write date of birth: 1989 06 28 and then click command button. Then in label i see result 43. Now i need the number of 43 sum. ( 4 + 3 = 7).And if lets say number is 93 then 9 + 3 = 12 = 1 + 2 = 3.
Finally. You added all the numbers from all text boxes to get 43!

Really starting to sound like HOMEWORK to me...

::calc to the rescue::
• October 5th, 2012, 04:50 AM
Halosar7
Re: [RESOLVED] How to calculate the total sum of the numbers
jggtz you are awesome! :):thumb: Thanks you, your code is works fine.
I really am begginer so can you tell my how "validate that every textbox has an integer number inside" ?
• October 5th, 2012, 09:25 AM
jggtz
Re: [RESOLVED] How to calculate the total sum of the numbers
Just following the example... isn't the best approach

First, in design time, to each textbox, set it's MaxLength property = 1

Code:

```    Dim intTotal1 As Integer     Dim strTotal1 As String     Dim intTotal2 As Integer         If IsNumeric(Text1.Text) And _       IsNumeric(Text2.Text) And _       IsNumeric(Text3.Text) And _       IsNumeric(Text4.Text) And _       IsNumeric(Text5.Text) And _       IsNumeric(Text6.Text) And _       IsNumeric(Text7.Text) And _       IsNumeric(Text8.Text) Then         intTotal1 = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) + Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text) + Val(Text7.Text) + Val(Text8.Text)         strTotal1 = Format(intTotal1, "00")         intTotal2 = Val(Left(strTotal1, 1)) + Val(Right(strTotal1, 1))         Label1.Caption = Format(intTotal2)     Else         MsgBox "Some of the textboxes has not a number"     Endif```
• October 5th, 2012, 11:32 AM
Halosar7
Re: [RESOLVED] How to calculate the total sum of the numbers
I did it, i set eatch textbox MaxLength property = 1.
How i continue write this code from And_
Code:

`If IsNumeric(Text1.Text) And _`
Show 50 post(s) from this thread on one page
Page 1 of 2 12 Last