Solved

Select 1 line at time

Posted on 2001-06-06
12
151 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

708 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

12 Experts available now in Live!

Get 1:1 Help Now