473,473 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question about Text Boxes

I have a multiline textbox with 10 lines of text in it. I want to search
Line by Line for the word" [Option]". How do I process one line in a text
box at a time? I DON'T want to just search the whole textbox for my word,
because when I find it, I want to stop the cursor there until the user
decides to continue to find the next instance.

MY QUESTION IS: How can I search for text line by line in a textbox?

Thank You,
Paul
Jul 17 '05 #1
2 2843
On Wed, 23 Jun 2004 23:50:55 -0700, "Newsgroup" <pm*@swannack.net>
wrote:
I have a multiline textbox with 10 lines of text in it. I want to search
Line by Line for the word" [Option]". How do I process one line in a text
box at a time? I DON'T want to just search the whole textbox for my word,
because when I find it, I want to stop the cursor there until the user
decides to continue to find the next instance.

MY QUESTION IS: How can I search for text line by line in a textbox?


Option Explicit
' Add one Textbox
' Set it to MultiLine

Private Declare Function SendMessage Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Declare Function SendMessageStr Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As String) As Long

Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETLINE = &HC4
Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEINDEX = &HBB
Private Sub Command1_Click()
Dim Lines&, S$, P&, L&
Const LINE_NO = 2

' --- Count the Lines
Lines& = SendMessage(Text1.hwnd, _
EM_GETLINECOUNT, _
0, _
0)
Me.Print Lines
' Note: If Text1.Text = "" then 1 is returned

' --- Now get position of start of 2nd line
' this is zero based
P& = SendMessage(Text1.hwnd, _
EM_LINEINDEX, _
LINE_NO - 1, _
0)
Me.Print "Line 2 Starts at:"; P
' --- Now Get its Length
L& = SendMessage(Text1.hwnd, _
EM_LINELENGTH, _
P, _
0)
Me.Print "Length of Line 2 is:"; L
' --- Now Get Line 2
S$ = Space$(L)
L& = SendMessageStr(Text1.hwnd, _
EM_GETLINE, _
LINE_NO - 1, _
S)
Me.Print S$
' --- And to prove it
Me.Print Mid$(Text1.Text, P + 1, L)

End Sub

Jul 17 '05 #2
> I have a multiline textbox with 10 lines of text in it. I want to
search
Line by Line for the word" [Option]". How do I process one line in a text box at a time? I DON'T want to just search the whole textbox for my word, because when I find it, I want to stop the cursor there until the user
decides to continue to find the next instance.

MY QUESTION IS: How can I search for text line by line in a

textbox?

I'm not sure why you don't simply want to skip down through all the
words you want to find. Put the following code in a CommandButton and
load up your TextBox with text containing the word you want to find (in
this case, " [Option]", with the leading space as shown). Now keep
pressing the button and watch the TextBox.

Rick - MVP

Dim Position As Long
Dim WordToFind As String
WordToFind = " [Option]"
With Text1
If .SelLength Then .SelStart = .SelStart + .SelLength
Position = InStr(.SelStart + 1, .Text, WordToFind)
If Position Then
.SelStart = Position - 1
Else
.SelStart = InStr(.Text, WordToFind) - 1
End If
.SelLength = Len(WordToFind)
.SetFocus
End With

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lance Geeck | last post by:
Hi, I am trying to learn the VB.NET approach and am having problems with updating the database. What I have is a simple windows form using text boxes for entering name, address and phone. It is...
7
by: jimi_xyz | last post by:
I am kind of new to C sharp; I have a quick question I have multiple text boxes 12 of them to be exact. What I want to do is fill them with values that are in a array of integers. The way I am...
3
by: eBob.com | last post by:
I have several applications which mine web sites for personal information which they publish. They publish the info in one form, I transform the info into Excel spreadsheets. So all these...
0
by: Brian Cesafsky | last post by:
I am using framework 1.1 I have a user control and a web page. I want to set up properties on the user control, so I can access the text boxes on the user control when I am in the code behind...
0
by: Brian Cesafsky | last post by:
I am using framework 1.1 I have a user control and a web page. I want to set up properties on the user control, so I can access the text boxes on the user control when I am in the code behind...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
1
by: JDeats | last post by:
So I have a new WebForm created in VS.NET 2005 that's in the default "flow layout". I have a dropdown list box followed by HTML break- return <brtags and two two text boxes, below the text boxes I...
15
by: Matthew | last post by:
Hi, I'm mainly a coder, PHP at the moment, but from time to time need to design and use some css. I've a css text alignment issue. Mostly to align text neatly in the past I've used tables....
2
by: Lynx101 | last post by:
Hi, Is this a stupid question? Senario: Two tables linked together with an ID number. Question: When using a combo box, which refences another table by indexed autonumber, is there a way to...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.