justin05
asked on
textbox problem
i need to be able to get a line from one multiline textbox and place that line into a single line textbox then delete the original line from the multiline textbox. im looking for simple code something that could be easly understood
is it a particular line in the multiline textbox or will it be some random line??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub text1_DblClick()
Text2.Text = Text1.SelText
Text1.SelText = ""
End Sub
Text2.Text = Text1.SelText
Text1.SelText = ""
End Sub
hes, that wont highlight the entire line
My version:
Option Explicit
Const EM_LINELENGTH = &HC1
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) _
As Long
Private Sub Command1_Click()
Dim lChar As Long, lLine As Long, lLen As Long
Dim lLineIndex As Long
With txtMulti 'Multiline textbox
lChar = .SelStart
'Get the absolute line number
lLine = SendMessage(.hwnd, EM_LINEFROMCHAR, lChar, 0)
'Get the char pos of beginning of line
lLineIndex = SendMessage(.hwnd, EM_LINEINDEX, lLine, 0)
'Get the length of the line
lLen = SendMessage(.hwnd, EM_LINELENGTH, lChar, 0)
.SelStart = lLineIndex
.SelLength = lLen
'Copy over to the other textbox
txtLine.Text = Trim(.SelText)
'Clear the text
.SelText = ""
End With
End Sub
Option Explicit
Const EM_LINELENGTH = &HC1
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) _
As Long
Private Sub Command1_Click()
Dim lChar As Long, lLine As Long, lLen As Long
Dim lLineIndex As Long
With txtMulti 'Multiline textbox
lChar = .SelStart
'Get the absolute line number
lLine = SendMessage(.hwnd, EM_LINEFROMCHAR, lChar, 0)
'Get the char pos of beginning of line
lLineIndex = SendMessage(.hwnd, EM_LINEINDEX, lLine, 0)
'Get the length of the line
lLen = SendMessage(.hwnd, EM_LINELENGTH, lChar, 0)
.SelStart = lLineIndex
.SelLength = lLen
'Copy over to the other textbox
txtLine.Text = Trim(.SelText)
'Clear the text
.SelText = ""
End With
End Sub
ASKER
this code did not answer my but i found the answer i was looking for thanks for the help though i did this very simply by doing the following
teststring = Text1
For scan = 1 To Len(teststring)
splited = Mid(teststring, scan, 1)
If splited = Chr(10) Then
endline = scan
scan = Len(teststring)
End If
Next scan
textedit = Left(teststring, endline)
strfind = textedit.Text
intlen = Len(strfind)
Text1.SelStart = 0
Text1.SelLength = intlen
Text1.SelText = ""
as you can see this is very simple and it worked for what i was doing thank you all for your help
teststring = Text1
For scan = 1 To Len(teststring)
splited = Mid(teststring, scan, 1)
If splited = Chr(10) Then
endline = scan
scan = Len(teststring)
End If
Next scan
textedit = Left(teststring, endline)
strfind = textedit.Text
intlen = Len(strfind)
Text1.SelStart = 0
Text1.SelLength = intlen
Text1.SelText = ""
as you can see this is very simple and it worked for what i was doing thank you all for your help
You need to use the Cut, Copy & Paste options.
First you get the current cursor position ie the start of the blocked text or the start of the line.
Then from there you use the mid function to cut the portion and add this to the textbox.
First you get the current cursor position ie the start of the blocked text or the start of the line.
Then from there you use the mid function to cut the portion and add this to the textbox.