Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetLine Function For Visual Basic

Posted on 2003-11-20
2
Medium Priority
?
942 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
[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
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 375 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

688 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