Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Select 1 line at time

Posted on 2001-06-06
12
Medium Priority
?
172 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

971 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