| | |
Removing First Line Of Text From multiline textbox
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
![]() |
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
Hi all I am kind of new to vb.net, and am wondering if anyone could tell me how I can remove the first line of text from a multiline textbox. Let's say I load a text file with 50 lines into a multiline textbox. How do I delete the first line of text from the textbox and have 49 lines left? Any help will be greatly appreciated.
satellites101
satellites101
First, you need the following declarations:
Now, I placed this code in a button click event :
Counter set = 1 to start from second line.
See the pic
vb.net Syntax (Toggle Plain Text)
Private Const EM_GETLINECOUNT As Integer = &HBA Private Const EM_GETLINE As Integer = &HC4 Private Const EM_LINELENGTH As Integer = &HC1 Private Const EM_LINEINDEX As Integer = &HBB Private Declare Function SendMessageINT Lib "user32.dll" _ Alias "SendMessageA" (ByVal hWnd As IntPtr, _ ByVal wMsg As Integer, ByVal wParam As Integer, _ ByVal lParam As IntPtr) As Integer
Now, I placed this code in a button click event :
Counter set = 1 to start from second line.
vb.net Syntax (Toggle Plain Text)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim LineCount As Integer = SendMessageINT(TextBox1.Handle, EM_GETLINECOUNT, 0, IntPtr.Zero) Dim counter As Integer = 0 Dim LineIndex As Integer = 0 Dim lineLength As Integer Dim curLine As String = "" Dim stringPTR As IntPtr For counter = 1 To LineCount - 1 'Get Index for line we want to retrieve LineIndex = SendMessageINT(TextBox1.Handle, EM_LINEINDEX, counter, IntPtr.Zero) 'GetLineLength lineLength = SendMessageINT(TextBox1.Handle, EM_LINELENGTH, LineIndex, IntPtr.Zero) 'Create the buffer curLine = New String("0"c, lineLength + 2) Mid(curLine, 1, 1) = Chr(lineLength And &HFF) Mid(curLine, 2, 1) = Chr(lineLength \ &H100) 'Get the pointer for a buffer stringPTR = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(curLine) 'Fill the pointer with the current line SendMessageINT(TextBox1.Handle, EM_GETLINE, counter, stringPTR) 'Read the line curLine = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(stringPTR) curLine = curLine.Substring(0, lineLength) 'fill textbox2 TextBox2.Text = TextBox2.Text + curLine + vbCrLf 'clear out the space System.Runtime.InteropServices.Marshal.FreeHGlobal(stringPTR) stringPTR = IntPtr.Zero Next End Sub
See the pic
Last edited by Jx_Man; Aug 26th, 2008 at 1:24 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
1) Drag a text box onto your form. Make sure the multiline option is true
2) Drag a button onto your form
2) Drag a button onto your form
vb Syntax (Toggle Plain Text)
Imports System.io Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'read in file Dim objReader As New StreamReader("C:\test.txt") Dim sLine As String = "" Dim lineCounter As Integer = 0 Do sLine = objReader.ReadLine() If lineCounter > 0 Then TextBox1.Text = TextBox1.Text + sLine + System.Environment.NewLine End If lineCounter = lineCounter + 1 Loop Until sLine Is Nothing objReader.Close() End Sub End Class
Last edited by iamthwee; Aug 26th, 2008 at 8:12 am.
*Voted best profile in the world*
Great Code iamthwee
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
If you want short and simple, try this:
VB.NET Syntax (Toggle Plain Text)
Dim b As String() = Split(TextBox1.Text, vbNewLine) TextBox1.Text = String.Join(vbNewLine, b, 1, b.Length - 2)
Wayne
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
If you want short and simple, try this:
VB.NET Syntax (Toggle Plain Text)
Dim b As String() = Split(TextBox1.Text, vbNewLine) TextBox1.Text = String.Join(vbNewLine, b, 1, b.Length - 2)
VB.NET Syntax (Toggle Plain Text)
TextBox1.Text = String.Join(vbNewLine, b, 1, b.Length - 2)
VB.NET Syntax (Toggle Plain Text)
TextBox1.Text = String.Join(vbNewLine, b, 1, b.Length - 1)
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: please i want to make contact details program with VB
- Next Thread: Save picture in access
| Thread Tools | Search this Thread |
.net .net2005 .net2008 30minutes 2005 2008 access account arithmetic array basic browser button buttons center check code component connectionstring crystalreport cuesent data database databasesearch datagrid datagridview date datetimepicker design dissertation dissertations dissertationthesis dissertationtopic dropdownlist excel fade file-dialog filter folder ftp generatetags hardcopy image images input insert intel monitor net networking opacity output panel passingparameters peertopeervideostreaming picturebox picturebox1 port printing problem problemwithinstallation project reports" savedialog searchvb.net select serial settings shutdown string survey tcp temperature text textbox timer timespan toolbox transparency trim updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year






