I want to Know is there any way to get sum of numbers which entered in single textbox in VB6
as a example; i have textbox named txt1 in that user can type any value (12+23+34+12....) (separate the values by adding "+").when the user click the command button, i want to get the Sum of those values to a variable/textbox or label.
i searched over the internet and found a option to get values separatly by using "split" funtion, but i cant get sum of those. plese help me.
Have a look at the Len function, Left and Right functions with split. Basically you need to split the string into values before the + sign. Once you get that value, just add them together...
InStr will probably work the best...
If InStr(1, TheString, "+") > 0 Then
MsgBox "+ found!"
''Your code here to start adding values...
The below code will count the amount of plusses in the string...
Private Function CountChars(ByVal sText As String, iCharacter As Integer) As Long
Dim TextArray() As Byte
Dim i As Long
Dim lCount As Long
TextArray() = sText
For i = 0 To UBound(TextArray) Step 2
If TextArray(i) = iCharacter Then lCount = lCount + 1
CountChars = lCount
'35 is the ascii code for the # sign
Private Sub Command1_Click()
Dim CallIt As Long
CallIt = CountChars(Text1.Text, 35)
Or something similar...
' count +
Dim asciiToSearchFor As Integer
asciiToSearchFor = Asc("+")
For i = 1 To Len(text)
If Asc(Mid$(text, i, 1)) = asciiToSearchFor Then count = count + 1
With the above you can now put together exactly what you need.