sum multiline textbox
- hi a have to do a project for my class(so totally a noob in vb2008) and i need to sum the values of all lines in a multi line textbox and displayy them in a second text box.
i will really appreciate any help you guys can lend me.
Answers
Hi amorales,
Welcome to MSDN forums!
Please check the following code sample and try to understand it.
Prerequisites:
1. Drag & drop TextBox1, TextBox2 and Button1 onto Form1.
2. You need to input valid numeric value at each line into multi-line TextBox1.Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Multiline = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sum As Double
Dim line As String
Try
For Each line In TextBox1.Lines
sum = sum + Double.Parse(line.Trim)
Next
TextBox2.Text = sum
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorMonday, October 19, 2009 8:51 AM
All Replies
Hi amorales,
Welcome to MSDN forums!
Please check the following code sample and try to understand it.
Prerequisites:
1. Drag & drop TextBox1, TextBox2 and Button1 onto Form1.
2. You need to input valid numeric value at each line into multi-line TextBox1.Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Multiline = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sum As Double
Dim line As String
Try
For Each line In TextBox1.Lines
sum = sum + Double.Parse(line.Trim)
Next
TextBox2.Text = sum
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorMonday, October 19, 2009 8:51 AM
Besides, here are some suggestions, tutorial, code samples for VB.NET programming beginners.
Some suggestions to Junior Programmershttp://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/c8e4089d-6973-454c-8180-367061891b90
Absolute Beginner’s Video Series
http://msdn.microsoft.com/en-us/vstudio/aa700732.aspx
Learn the Visual Basic Language (How Do I in Visual Basic)
http://msdn.microsoft.com/en-us/library/ms172564.aspx
How Do I in Visual Basic
http://msdn.microsoft.com/en-us/library/ms172558.aspx
MSDN Beginner Developer Learning Center
http://msdn.microsoft.com/en-us/beginner/default.aspxMany code samples for you to download.
101 Visual Basic and C# Code Samples
Visual Basic .NET Code Samples: Master Set of 101 SamplesVisual Basic .NET General FAQ
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/5f2a5f51-169b-4b56-89d6-01b1d314fdf0
Visual Basic Express FAQ
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/ab6675a0-44c2-4d92-a4f7-2b6332e4092cDownload Visual Basic 2008 Express Edition
http://www.microsoft.com/express/download/
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


