I am desgining a userform in ArcMap, but I don't know how to sum up numeric values in a textbox (txtBox1) in another textox (txtBox2). Can anybody provide me with a vba code for that!

Since you are using textbox, the data that you will input into it is treated as text. Therefore, you need to convert it to numeric value in able to do the summing.
I think, you can use the VAL function to do that.

Can you give an example output?

Thanks. Would you please provide me with the Val code for summing up.

-->>Asumming that you have a command button named Sum...
-->>Then under its event click,just try to code the following...

Private Sub Sum_Click()
txtBox2.Text = Val(txtBox2.Text) + Val(txtBox1.Text)
End Sub

-->>If I did understand the question "I am desgining a userform in ArcMap,..." becouse I dont know what the ArcMap is...
-->>But as far as what is just needed to add the Numbers the above code may help or just give a light...
-->>Thanks.

Thanks! That is not what I mean. am adding numbers (curency) to Texbox1 but I want to sum up (total) these numbers in Textbox2 (or a label) with a mouse click on a command box. For examp-le, I will have many amounts of money entered into Textbox1 and I want their total to be displayed in textbox2.

You can use the following then.

Dim x As Integer ''Will hold the amount, must be only in numbers, otherwise use x as string...

''Do the calculation BEFORE you add the next amount to your textbox. If you were using a listbox, it would have been much easier...
x = "0"

x = x + 10 The first amount, then the second etc...

Text2.Text = x

Thanks! How we would relate these codes to Text1.text and command button? Line no. 6 is not an acceptable vba code. Would you please send to me the codes again!

My bad, there is a comment after the 10. Should be...

x = x + 10
''The first amount, then the second etc...

I have no idea what you mean by

How we would relate these codes to Text1.text and command button

Please give me more information...

Thanks! I have 2 text boxes. Textbox1 for entering numbers (amounts of money). I want to sum up (add) values of textbox 1 in textbox2. So, i have a commandbutton; i want to calculate sum of values of textbox 1 whenever i click on commandbutton. the sum (total) should appear in textbox2.

Easy, just declare the x integer BEFORE any subs...

Option Explicit

Dim x As Integer

''All your subs/macros will follow now...

Now, when you add the values to your textbox 1, use the code I gave you...

''Do the calculation BEFORE you add the next amount to your textbox. If you were using a listbox, it would have been much easier...
x = "0"
x = x + 10 
''The first amount, then the second etc...

The x will hold the value until you call it or clear it, so in your button click event...

Text2.Text = x

Thanks Andre! That codes did not work out unfortunately; the total created was always 10. To explain more, I have a textbox, a label (caption) and a commandbutton on a userform in arcmap - ArcGis. I use the textbox for enterying values (amounts of money). i want to sum (calculate total of the amounts in textbox in the label.caption, by clocking the commandbutton.

I think the problem might lie with arcmap, not sure. are you using armaps within visual basic 6 or in vba (excel etc)?

In other words, which applications textbox and label are you using?

Yes, i am using visual basic 6. to explain more, i have a userform with a textbox, a label and a command button. I use thetextbox for entering numbers (ammounts of money). i want to sum (calculate total of) the values entered into the textbox and display them in the label (.caption) using the command button.

Ok,

1st use a listbox to add the amounts and not a text box. then use the following code...

In your form, a listbox names lstAmounts, a command button named cmdCalculate, a label named lblSum... I'm adding auto amounts to the listbox, not sure where your data is coming from....

Option Explicit

Dim xSum As String, xList As Integer

Private Sub cmdCalculate_Click()

lstAmounts.AddItem "250"
lstAmounts.AddItem "150"
lstAmounts.AddItem "350"
lstAmounts.AddItem "50"
lstAmounts.AddItem "450"
lstAmounts.AddItem "100"
lstAmounts.AddItem "225"

xSum = "0"

For xList = 0 To lstAmounts.ListCount - 1
    lstAmounts.ListIndex = xList

    xSum = Val(xSum) + Val(lstAmounts.Text)

    lblSum.Caption = "$ " & xSum & ".00"
Next xList
End Sub

Thanks AndreRet! It worked out.

It is a pleasure. Please mark this as solved thanx. :)

when i type two values in a textbox so answer should be total of bothh values in same textbox like excel cell..?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.