Solved

GetLine Function For Visual Basic

Posted on 2003-11-20
2
899 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

771 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

10 Experts available now in Live!

Get 1:1 Help Now