Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I am lazy, 125 easy points :)  [line from a text box]

Posted on 1998-06-15
6
Medium Priority
?
165 Views
Last Modified: 2010-05-03
I want a function (or api call, I believe there is one) to grab a specific line from a rich text box.

For example, you are happily typing along, and just to be annoying I wanted this program to pop up a message box whenever you pressed enter at the end of a line and display the line you just finished typing....

1 : This is the first line (enter)
2 : this is the second line (enter)
blah blah blah

After I type the first line "This is the first line" and then pressed enter, a message box would appear with the line I just finished typing "This is the first line" and my cursor would be sitting on the next line like normal, nothing has changed.

Wow, that was a mouthful.  I do not think this is two hard, but I am lazy and working on other things, so hopefully someone can get some easy points.  This is in VB5 Professional.

Thanks,
oreg
0
Comment
Question by:oreg
6 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1463345
Dim szStr as string
SendMessage(text1.hwnd, EM_GETLINE, 2, szStr)
0
 

Author Comment

by:oreg
ID: 1463346
Hi, that answer actually does nothing.  Nothing is saved in the
string variable...at least not when I tested it on a RichTextBox
(never tried textbox, but that is not what I want).
0
 

Expert Comment

by:DanielJenkins
ID: 1463347
Dim pos As Integer

Private Sub Form_Load()
   pos = 0
End Sub

Private Sub rtBox_KeyPress(KeyAscii As Integer)
   If KeyAscii = 13 Then
      msgbox Mid$(rtBox.Text, pos + 1, Len(rtBox.Text) - pos)
      pos = Len(rtBox.Text) + 2
   End If
End Sub

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:oreg
ID: 1463348
This would work only in the specific case I gave above, the real task is to grab a line from the text box....any given line at a time...the example was just meant to show one possible use.

0
 
LVL 9

Accepted Solution

by:
Dalin earned 800 total points
ID: 1463349
oreg,
See if I undersatnd what you need: Let me know if you have questions
Regards
Dalin

'This routine grabs a line (you specify the line number) of a 'textbox

'Declare

          Const EM_GETLINE = &HC4
          Const EM_LINELENGTH = &HC1
          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 Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)


          Sub TB_GetLine(ByVal hWnd As Long, ByVal whichLine As Long, Line As String)
              Dim length As Long, bArr() As Byte, bArr2() As Byte, lc As Long

              lc = SendMessage(hWnd, EM_LINEINDEX, whichLine, ByVal 0&)
              length = SendMessage(hWnd, EM_LINELENGTH, lc, ByVal 0&)
              If length > 0 Then
                  ReDim bArr(length + 1) As Byte, bArr2(length - 1) As Byte
                  Call RtlMoveMemory(bArr(0), length, 2)
                  Call SendMessage(hWnd, EM_GETLINE, whichLine, bArr(0))
                  Call RtlMoveMemory(bArr2(0), bArr(0), length)
                  Line = StrConv(bArr2, vbUnicode)
              Else
                  Line = "" 
              End If
          End Sub

To read the 5th line and put in the string of lString

Dim lString As String
Call TB_GetLine( Text1.hWnd, 5, lString )

MsgBox "The 5th Line is " & lString, vbOKOnly, "Read a Line"
0
 

Author Comment

by:oreg
ID: 1463350
That code is amazing, I tried to break it but I couldn't :)  Thank you very much, I will throw in a few more points for you since this works so well.  If you have a chance later, could you briefly walk me through it (the API calls that is).

Thanks again,
oreg.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question