GetLine Function For Visual Basic

Posted on 2003-11-20
Last Modified: 2013-11-25
I don't know why I am having so much trouble trying to do this but anyway I need a function that reads 1 line of text from a textbox that is multi-line enabled.

Example of what I need:
Textbox named "txtboxInfo" will have
"21 name <vbCrLF>
22 name1 <vbCrLF>
23 namebn <vbCrLF>"

I need my function which will be called in a loop to get each line and return the line as a string
So if would write  
Dim strInfo As string
Do while (txtboxInfo <> "" )
   strInfo = Getline(txtboxInfo.text)

So that loop should run 3 times and return the following results
Run |  Result
1     |  21  name
2     |  22  name1
3     |  23  namebn

Anyway I don't know why I can't writes this Maybe cause I have been programming for like the last month straight and jumping between java, VB, and C++ So thanks for the help

Question by:vbhelp12345
LVL 43

Accepted Solution

TimCottee earned 125 total points
ID: 9786060
Hi vbhelp12345,


Dim aryLines() As String
Dim intLine As Integer
Dim strLine As String
aryLines = Split(txtboxinfo.Text,vbCrLf)
For intLine = LBound(aryLines) To UBound(aryLines)
  strLine = CStr(intLine + 1) & " | " & aryLines(intLine)
  Msgbox strLine

This simply splits the contents of the texbox to an array and then scans the array to display each line

Brainbench MVP for Visual Basic

Author Comment

ID: 9786195
Oh here is my final test program with it implemented

Dim aryLines() As String
Private Sub Command1_Click()

Dim x As Integer
Dim y As Integer
y = Getline(Text1.Text)
For x = 0 To y - 1
MsgBox aryLines(x)
End Sub

Private Sub Command2_Click()
End Sub

Private Sub Form_Load()
Dim i As Integer
i = 1
Text1.Text = str(i) + " " + str(i * 23) + vbCrLf
For i = 2 To 29
    Text1.Text = Text1.Text + str(i) + " " + str(i * 23) + vbCrLf
End Sub

Function Getline(strq As String) As Integer
Dim intLine As Integer
Dim strLine As String
aryLines = Split(strq, vbCrLf)
For intLine = LBound(aryLines) To (UBound(aryLines) - 1)
  strLine = aryLines(intLine)

Getline = intLine
End Function

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is MicroStrategy.NET? 2 72
Prevent checkbox click event occur while editing it in vb6 8 57
VBA Shell can't Find Word document 11 112
Please explain purpose of GZIP 4 35
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

828 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