Solved

GetLine Function For Visual Basic

Posted on 2003-11-20
2
927 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 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

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…

739 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