Solved

Select 1 line at time

Posted on 2001-06-06
12
153 Views
Last Modified: 2010-07-27
Would someone be kind enough to help me.

I need a function that accepts a string (not from a text file on the HD),
and selects 1 line at a time by putting that line into another string.

I shall do something with that string and reconstruct the original text,
but it is imperative that the function reads 1 line at a time.

Thank you.
0
Comment
Question by:idcanada
12 Comments
 
LVL 2

Expert Comment

by:agriggs
ID: 6160954
Your question puzzles me because you said you want to read a string 1 line at a time, and you specified that it was "not from a text file on the HD", but you didn't specify where it was going to be reading it from?

If it was to be read from a text file on the hard drive, you could use the Line Input function of VB.
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6160976
if it is from a text file from of the hard drive then you can do something like this

private command1_click()
on error goto errorhandler:
dim store as string


open "c:\text.txt" for input as #1
do while not eof(1)
input#1,store
wend

close#1

errorhandle:
close#1

end sub


This will allow you to read the text file into store.

you can then build of store using mids or what ever to do what you need to do with the string.

please note that is only an example of how to read information from a file in to a string.

Many Thanks
Andy
 
0
 
LVL 6

Accepted Solution

by:
JonFish85 earned 50 total points
ID: 6161041
if you have a string like this:

This
is
four
lines

you can put each line into a part of an array like this:

'strMultipleLines is the text above ^
Dim strArray() As String
strArray = Split(strMultipleLines, vbCrLf)

now strArray(0) = "This"
strArray(1) = "is"
strArray(2) = "four"
strArray(3) = "lines"
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 2

Expert Comment

by:Microsoft
ID: 6161302
'strMultipleLines is the text above ^
Dim strArray() As String
strArray = Split(strMultipleLines, vbCrLf)

now strArray(0) = "This"
strArray(1) = "is"
strArray(2) = "four"
strArray(3) = "lines

ill be a copy cat and pinch jons idea

lol

sorry jon

just want some points CRY

:o(
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6161585
whoa desperate?! :-D
0
 
LVL 4

Author Comment

by:idcanada
ID: 6161587
JonFish85, I think you have solved my question.
Will test it tomorrow and will award you the points if it works.

** I am sure it will **

Thank you.
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6161601
BTW, that will only work if the lines are separated by both a carriage return and a new line character. If only one of the characters is present, then you can replace vbCrLf with either chr(13) or chr(11) depending on which is in your string.

Zaphod.
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6161699
i was desp for points Jon .... :o)

fayb has just accepted my code for dialing a phone number from a listbox list.

hehehe what it Jon, im coming after ya

:op

cheers Andy
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6161702
watch it I mean
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6161737
whoa Im scared :-)
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6163712
Microsoft, this is a friendly warning. Please don't (even in jest) copy other's comments. If you do so in future I will have no hesitation in referring your account to customer services.

Remember that Expert points <> question points so there really should be no desperation involved in getting expert points. You have 1200 and jon has 25000+, idcanada has 40000+ so don't get too keen or you will irritate not only the questioner(s) but the other experts on the site.
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6164391
glad I could help!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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