-
[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.
-
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
-
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
-
Re: How to calculate the total sum of the numbers
So what you are trying to do is a numerology calcultaion?
-
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... :)
-
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
-
2 Attachment(s)
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)
-
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!
-
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.
-
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.
-
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
-
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!
Then you add 4+3?
Really starting to sound like HOMEWORK to me...
::calc to the rescue::
-
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" ?
-
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
-
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 _
-
Re: [RESOLVED] How to calculate the total sum of the numbers
The character _ means continuation line... just press Enter after _ and continue typing next line of code
-
2 Attachment(s)
Re: [RESOLVED] How to calculate the total sum of the numbers
I have another question for you.
For each 8 textbox i can enter any number i want.(from 0 to 9)
But how to do that on each textbox i can enter specific number? For example:
Attachment 30427
And i notice a mistake, look at this picture.
Attachment 30429
My C-button clear all textbox and leave them blank.
My code is this:
Code:
Dim intTotal1 As Integer
Dim strTotal1 As String
Dim intTotal2 As Integer
Private Sub Command1_Click()
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 "Laukelis paliktas tuščias arba įvestas ne skaičius!", vbInformation, "Dėmesio!"
End If
End Sub
Private Sub Command2_Click()
Dim Contrl As Control
For Each Contrl In Form1.Controls
If (TypeOf Contrl Is TextBox) Then Contrl.Text = ""
End Sub
-
Re: [RESOLVED] How to calculate the total sum of the numbers
Code:
Dim intTotal1 As Integer
Dim strTotal1 As String
Dim intTotal2 As Integer
Dim strTotal2 As String
Private Sub Command1_Click()
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
If Val(Text1.Text) <> 1 And Val(Text1.Text) <> 2 Then
MsgBox "Year must begin with 1 or 2"
Exit Sub
End If
If Val(Text5.Text & Text6.Text) < 1 Or _
Val(Text5.Text & Text6.Text) > 12 Then
MsgBox "Month must be between 01 and 12"
Exit Sub
End If
If Val(Text7.Text & Text8.Text) < 1 Or _
Val(Text7.Text & Text8.Text) > 31 Then
MsgBox "Day must be between 01 and 31"
Exit Sub
End If
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))
If intTotal2 > 9 Then
strTotal2 = Format(intTotal2, "00")
intTotal2 = Val(Left(strTotal2, 1)) + Val(Right(strTotal2, 1))
End If
Label1.Caption = Format(intTotal2)
Else
MsgBox "Laukelis paliktas tuščias arba įvestas ne skaičius!", vbInformation, "Dėmesio!"
End If
End Sub
Private Sub Command2_Click()
Dim Contrl As Control
For Each Contrl In Form1.Controls
If (TypeOf Contrl Is TextBox) Then
Contrl.Text = ""
End If
Next
End Sub
-
Re: [RESOLVED] How to calculate the total sum of the numbers
add another line of code. that's what _ means
-
1 Attachment(s)
Re: [RESOLVED] How to calculate the total sum of the numbers
Quote:
Originally Posted by
dglienna
add another line of code. that's what _ means
It means that we continue programing by fixing bug and i ask him about vb6 programing. That way i learning from his code.
-
1 Attachment(s)
Re: [RESOLVED] How to calculate the total sum of the numbers
Iy would be better if you start a new thread about transparency in VB6... anyway
Here's a small VB6 project about transparent form
I think this is better than explain here
-
Re: [RESOLVED] How to calculate the total sum of the numbers
Quote:
Originally Posted by
jggtz
Iy would be better if you start a new thread about transparency in VB6... anyway
Here's a small VB6 project about transparent form
I think this is better than explain here
Thanks :-)