Solved

GetLine Function For Visual Basic

Posted on 2003-11-20
2
901 Views
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)
loop

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

Later,
Aaron
0
Comment
Question by:vbhelp12345
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 125 total points
ID: 9786060
Hi vbhelp12345,

Use:

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
Next

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

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:vbhelp12345
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)
Next
End Sub

Private Sub Command2_Click()
End
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
Next
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)
Next

Getline = intLine
End Function
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

943 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now