vbnewby
asked on
sum a multiline textbox
As you can tell from my signon name, I am only new to VB (do a little VBA, Thought I would uprgrade.), but I have a problem, I have a multiline text box for the user to add a list of numbers. How do I get VB to add these numbers up? its probably something simple that I have missed (Can get it to work in VBA by using a Spreadsheet)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>its probably something simple that I have missed
Not really. Excel has functionality built in to perform summations, but VB is a general-purpose tool designed generically meaning that you have to do special-purpose things like this yourself.
The comments above should handle it. However, these will only work with VB6/Office 2000 VBA.
Not really. Excel has functionality built in to perform summations, but VB is a general-purpose tool designed generically meaning that you have to do special-purpose things like this yourself.
The comments above should handle it. However, these will only work with VB6/Office 2000 VBA.
ASKER
Thanks RD runner, almost had it myself, I missed the vbcrlf in the split.
Thanks guys
gotta love this site...
Thanks guys
gotta love this site...
No Problem, glad it works now ...
If you like this site, then grade the answer you like please ;)
Thanx
If you like this site, then grade the answer you like please ;)
Thanx
How about a single line of code?
Add the Miscrosoft Script control as a component reference and add it to your form. Then perform this single line:
MsgBox ScriptControl1.Eval(Replac e(Text1.Te xt, vbCrLf, "+"))
Add the Miscrosoft Script control as a component reference and add it to your form. Then perform this single line:
MsgBox ScriptControl1.Eval(Replac
ASKER
sorry Rdrunner,
thought I had passed these on to you....
thought I had passed these on to you....
if yes, split up the contents by the separator vbCrLf, and then add the items up:
dim strLines() as string
dim lngLoop as long
dim lngvalue as Long
dim lngTotal as long
strLines = Split(yourTextbox.text, vbCrlf)
lngTotal= 0
for lngLoop = lbound(strLines) to ubound(strLines)
lngValue = val(strLines(lngLoop))
lngTotal = lngTotal + lngValue
next
msgbox lngTotal
CHeers