| | |
Sum of the numbers of one textbox
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 10
Reputation:
Solved Threads: 4
I'm not sure if the solution is so easy as you write... VB(at least my 6 one) does not have the sum function... its necessary to write it at first. It could looks like this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Public Function SUM(sNumber as String) As Integer dim iX as integer, iCount as integer for iX = 1 to len(sNumber) iCount = iCount + CInt(Mid(sNumber, iX, 1)) Next iX SUM = iCount End Function
•
•
Join Date: Oct 2009
Posts: 18
Reputation:
Solved Threads: 0
0
#6 Oct 26th, 2009
•
•
•
•
I'm not sure if the solution is so easy as you write... VB(at least my 6 one) does not have the sum function... its necessary to write it at first. It could looks like this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Public Function SUM(sNumber as String) As Integer dim iX as integer, iCount as integer for iX = 1 to len(sNumber) iCount = iCount + CInt(Mid(sNumber, iX, 1)) Next iX SUM = iCount End Function
•
•
Join Date: Mar 2009
Posts: 914
Reputation:
Solved Threads: 167
0
#7 Oct 26th, 2009
Lida_Pink,
Lets make sure of our definitions first... The sum of numbers is, those numbers being added together, while the product of numbers is, those numbers being multiplied together. So if you want the sum of numbers in a string then celt.max's code does work...
However, if you are wanting the product of the numbers, then yes a different solution is needed. So, are you wanting the product of these numbers?
Good Luck
Lets make sure of our definitions first... The sum of numbers is, those numbers being added together, while the product of numbers is, those numbers being multiplied together. So if you want the sum of numbers in a string then celt.max's code does work...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Option Explicit Private Sub Form_Load() Dim Result As Integer Result = SUM("1234") MsgBox Result End Sub Public Function SUM(sNumber As String) As Integer Dim iX As Integer, iCount As Integer For iX = 1 To Len(sNumber) iCount = iCount + CInt(Mid(sNumber, iX, 1)) Next iX SUM = iCount End Function
However, if you are wanting the product of the numbers, then yes a different solution is needed. So, are you wanting the product of these numbers?
Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.
Thanks
Thanks
•
•
Join Date: Jan 2008
Posts: 255
Reputation:
Solved Threads: 38
0
#8 Oct 26th, 2009
Try the following to get the sum of an integer -
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Command1_Click() On Error GoTo Errorhandler x = InputBox("Please Enter an Integer.", , Text1.Text) If x <> "" Then List1.AddItem Str(x) Do While x <> 1 If x Mod 2 = 0 Then x = x / 2 Else x = (x * 3) + 1 End If List1.AddItem Str(x) Loop 'Number of steps used Label1 = List1.ListCount - 1 End If Errorhandler: Exit Sub End Sub 'Even numbers are divided by 2 'Odd numbers are multiplied by 3 and are then increased by 1 'The problem ends by reaching the number 1
Please mark questions as answered when done.
Be the ONE!!!
Be the ONE!!!
![]() |
Similar Threads
- Code Snippet: Sum of numbers (Assembly)
- Code Snippet: Smallest, Largest & Sum of 5 numbers (C)
- need help getting program to sum numbers (Java)
- Sum of Positive and Negative numbers (C++)
- Displaying the Sum of Even and Odd numbers (C++)
- Sum of numbers will not display (Assembly)
- need help, need to generate 10 random numbers, such that their sum is less than 1 (C)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: datagrid in vb6 problem
- Next Thread: Encrypt and Decrypt
Views: 556 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
6 429 2007 access activex add age append application basic beginner birth c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





