Solved

Select 1 line at time

Posted on 2001-06-06
12
158 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
[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
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

752 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