|
-
Feb 13th, 2009, 07:24 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Find line on multiline textbox
I have PokerLast.text 3 lines of text.
I need a function that will find the line with "Your cards" and return that full line. not any other lines.
text1.text = GetLine(PokerLast.text, "Your cards")
and text1.text will now display that line. I asked somthing before to get the "lineafter" but now i need to return the current line?
-
Feb 13th, 2009, 07:36 PM
#2
Re: Find line on multiline textbox
Code:
Private Function GetLine(sTxt As String, sFind As String) As String
Dim s() As String
Dim i As Integer
s = Split(sTxt, vbCrLf)
For i = 0 To UBound(s)
If InStr(1, s(i), sFind) > 0 Then ' Case sensitive find
GetLine = s(i)
Exit For
End If
Next i
End Function
-
Feb 13th, 2009, 07:39 PM
#3
Thread Starter
Addicted Member
Re: Find line on multiline textbox
Thanks! that worked 1st time perfectly. I love this fourm!
-
Feb 13th, 2009, 07:40 PM
#4
Re: Find line on multiline textbox
Code:
Option Explicit
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 Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEINDEX = &HBB
Private Const EM_GETLINE = &HC4
Private Sub Command1_Click()
Dim lngCount As Long
Dim lngLineIndex As Long
Dim lngLength As Long
Dim strBuffer As String
Dim lngIndex As Long
'Get the line count
lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
With Text1
For lngIndex = 0 To lngCount - 1
'Get line index of the chosen line
lngLineIndex = SendMessage(.hwnd, EM_LINEINDEX, lngIndex, 0)
'get line length
lngLength = SendMessage(.hwnd, EM_LINELENGTH, lngLineIndex, 0)
' 'resize buffer
strBuffer = Space(lngLength)
' 'get line text
Call SendMessageStr(.hwnd, EM_GETLINE, lngIndex, ByVal strBuffer)
If InStr(1, strBuffer, "your cards") Then
MsgBox strBuffer
Exit For
End If
Next
End With
End Sub
-
Feb 13th, 2009, 07:41 PM
#5
Re: Find line on multiline textbox
Now that we've helped you, you can help us by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item which will let everyone know that you have your answer. Also if someone has been particularly helpful you have the ability to affect a their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see it and know that you appreciate their help.
-
Feb 13th, 2009, 11:56 PM
#6
Re: Find line on multiline textbox
Nice one Martin. I have always preferred "SendMessage" over "split". SendMessage lets you interact like no other...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 14th, 2009, 01:38 AM
#7
Re: Find line on multiline textbox
 Originally Posted by koolsid
Nice one Martin. I have always preferred "SendMessage" over "split". SendMessage lets you interact like no other...
That is actually a bad example for what I think the OP wants to do, For example if the text is wrapped in the text box you won't get the full text result back or it may not even find the text you are after if the search words just so happen to be split (wrapped) on separate lines.
-
Feb 14th, 2009, 01:49 AM
#8
Re: Find line on multiline textbox
No Edge, It is not a bad example 
I have just posted to similar queries today... and sendmessage is a very "professional" way of handling textbox, RTB lines of text...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 14th, 2009, 02:23 AM
#9
Re: Find line on multiline textbox
 Originally Posted by koolsid
No Edge, It is not a bad example
I have just posted to similar queries today... and sendmessage is a very "professional" way of handling textbox, RTB lines of text...
But if the words you are searching for are broken/wrapped on separate lines then the code above will never find them.
Last edited by Edgemeal; Feb 14th, 2009 at 02:34 AM.
-
Feb 14th, 2009, 02:30 AM
#10
Re: Find line on multiline textbox
I am not sure if I understand... can you post an example?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 14th, 2009, 02:34 AM
#11
Re: Find line on multiline textbox
-
Feb 14th, 2009, 02:43 AM
#12
Re: Find line on multiline textbox
Naturally "are wrapped" are on two different line.
you can use sendmessage to check if a string is a particular line like OP wanted
I need a function that will find the line with "Your cards" and return that full line. not any other lines.
If it is not in one line then it will not be found.
If OP's query is to check if "Your cards" is in Textbox's text then I understand that you shouldn't be using sendmessage but that is not the case...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|