
October 3rd, 2012, 02:19 PM
#1
[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
If you know how to calculate better, please help me.

October 3rd, 2012, 02:39 PM
#2
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
#3
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
#4
Re: How to calculate the total sum of the numbers
So what you are trying to do is a numerology calcultaion?
Always use [code][/code] tags when posting code.

October 3rd, 2012, 10:30 PM
#5
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 asis, just to give you something to play with...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

October 3rd, 2012, 10:31 PM
#6
Re: How to calculate the total sum of the numbers
Originally Posted by DataMiser
So what you are trying to do is a numerology calcultaion?
Yeah, looks like that...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

October 4th, 2012, 09:42 AM
#7
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.
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
#8
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
#9
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.
I SUGGEST FIRST YOU TRY ON YOUR VB6 AND THEN GIVE MY ADVICE. Because so far your advice is do nothing.

October 4th, 2012, 07:37 PM
#10
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.
Always use [code][/code] tags when posting code.

October 4th, 2012, 09:19 PM
#11
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
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

October 4th, 2012, 09:59 PM
#12
Re: How to calculate the total sum of the numbers
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!
Then you add 4+3?
Really starting to sound like HOMEWORK to me...
::calc to the rescue::

October 5th, 2012, 04:50 AM
#13
Re: [RESOLVED] How to calculate the total sum of the numbers
jggtz you are awesome! 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
#14
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
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

October 5th, 2012, 11:32 AM
#15
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 _
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.
Featured
