Solved

Select 1 line at time

Posted on 2001-06-06
12
155 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

828 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