Solved

Assign a particular line of text in a multi line text box to a string variable

Posted on 2002-04-04
5
151 Views
Last Modified: 2010-05-18
How can I assign a particular line of text in a multi line text box to a string variable?

Say for example the text box Text1 contains these text:

This is the first line
This is the second line
This is the third line

I would like to assign the text on the third line (i.e."This is the third line") to a variable

It is best that the function does not utilise vbCrLf or carriage return.

Hopefully the function can have the form :
Getline( Text1.Text,2) where Text1.Text is the text inside the textbox and 2 is the content of line 2 i.e. "This is the second line".

So to extract the second line to a variable, the code will be something like:

Variable1=Getline(Text1.Text,2)

Thanks a million for the help!
0
Comment
Question by:kkclub23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:falconew
ID: 6920204
kkclub23,
Why not to check the VBCRLF? I think it is the only way to getting the line you want.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6920282
http://www.vb-world.net/php-bin/printfriendly.php?articlepageid=74

Is an API solution that shows you how to achieve this.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6920284
You will also need to include the api declaration for sendmessage:

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 Const EM_GETLINE = &HC4
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6921548
Please maintain your open questions:

Questions Asked 11
Last 10 Grades Given A A A A B  
Question Grading Record 5 Answers Graded / 5 Answers Received

Thanks,
Anthony
0
 
LVL 4

Accepted Solution

by:
RichW earned 50 total points
ID: 6922395
'Declarations
Public Const EM_EMPTYUNDOBUFFER = 205
Public Const EM_CANUNDO = 198
Public Const EM_GETMODIFY = 184
Public Const EM_SETMODIFY = 185
Public Const EM_UNDO = 199

Public Const EM_CANPASTE = 1074
Public Const EM_FINDTEXT = 1080

Public Const EM_GETFIRSTVISIBLELINE = 206
Public Const EM_GETLINECOUNT = 186
Public Const EM_GETLINE = 196
Public Const EM_LINEFROMCHAR = 201
Public Const EM_LINEINDEX = 187
Public Const EM_LINELENGTH = 193

Public Const EM_EXLINEFROMCHAR = 1078
Public Const EM_LINESCROLL = 182
Public Const EM_SCROLLCARET = 183
Public Const EM_SETTABSTOPS = 203


Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lparam As Long) As Long
   
'Code
Dim sFileName As String
Dim Lines
Dim WinH As Long
Dim i As Integer
Dim LineLength As Long
Dim charOffset As Long
 
'Get the windows handle of the multiline text box
 WinH = txtFileName.hWnd
   
   'Get the number of lines in the mutiline text box called txtFileName
    Lines = SendMessage(WinH, EM_GETLINECOUNT, 0, 0)
         
    For i = 0 To Lines - 1
 
       'Retrieve the offset of first character in the line
        charOffset = SendMessage(WinH, EM_LINEINDEX, i, 0)
       'Now get the length of the line
        LineLength = SendMessage(WinH, EM_LINELENGTH, charOffset, 0)
       'Debug.Print LineLength
        sFileName = Mid$(txtFileName.Text, charOffset + 1, LineLength)
        Debug.Print sFileName
             
    Next i

0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Saving history changes to sub form 4 56
Advice in Xamarin 21 119
Remove Exif Orientation before adding image to db 9 62
Modify Text File with Excel Macro 13 46
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

737 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