?
Solved

Read each line of the text file with this code

Posted on 2003-03-07
10
Medium Priority
?
165 Views
Last Modified: 2012-05-05

here is my code:
this reads the first line of a text file and puts each char in an array (tableau).
I would like to do that but for each line of the text file  (using fso).
(this is gonna overwrite the data in the array, i know..thats what i want)


    Set textStreamObject = fso.OpenTextFile("data.tmp", 1, False, 0)
    tmp = textStreamObject.ReadLine
    ReDim tableau(1 To Len(tmp))
    i = 1
    Do While i <= Len(tmp)
        tableau(i) = Mid$(tmp, i, 1)
        i = i + 1
    Loop
    Wend
0
Comment
Question by:Punker51
[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
  • 6
  • 4
10 Comments
 
LVL 1

Expert Comment

by:winner21
ID: 8090810
The only thing you need is to make a recursion for your code, same as the operation for line 1. Please add the following code as your outer loop:


Dim strIn as string  ' the variable for holding the whole line stuff.

Open "data.tmp" For Input As #1
 
Do while not EOF(1)
   Line Input #1, strIn
   tmp=len(strin)
   ReDim tableau(1 To Len(tmp))
   i = 1
   Do While i <= Len(tmp)
       tableau(i) = Mid$(tmp, i, 1)
       i = i + 1
   Loop
   Wend
  Close #1
Loop
0
 

Author Comment

by:Punker51
ID: 8091278
To winner21: when i try this i get this eror: bad file name or number (on the do while not EOF() line)
0
 
LVL 1

Expert Comment

by:winner21
ID: 8091310
You must specify the path to the file name. If the data.tmp is under C:, the first line you should change to "C:\data.tmp".
0
Independent Software Vendors: 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!

 

Author Comment

by:Punker51
ID: 8091352
Winner21: i did
0
 
LVL 1

Expert Comment

by:winner21
ID: 8091356
by the way, if the file is a text file, you cannot use tmp as the extension name. This is the reason you get the error. By the way, there is a mistake in my code, the variable tmp I declared is for holding the length, please discard this variable, and replace all tmp by strln, or you can simply replace strln by tmp.

0
 
LVL 1

Expert Comment

by:winner21
ID: 8091364
this is because your file is empty or something else. PLease check your file and make sure there is somthing there.
0
 
LVL 1

Expert Comment

by:winner21
ID: 8091374
let me write this code for you quickly as i have to go home now.
0
 
LVL 1

Accepted Solution

by:
winner21 earned 120 total points
ID: 8091390
I have a text file under C: root and it contains the following info.

sdsdsdsd
hrgrgrfsd;'
jkyhjtyh

*********************

Code:

Private Sub Command1_Click()

Dim tmp

Open "c:\data.txt" For Input As #1

Do While Not EOF(1)
  Line Input #1, tmp
 
  ReDim tableau(1 To Len(tmp))
  i = 1
  Do While i <= Len(tmp)
      tableau(i) = Mid$(tmp, i, 1)
      Debug.Print tableau(i)
      i = i + 1
  Loop
 
Loop
Close #1
End Sub


Result:

s
d
s
d
s
d
s
d
h
r
g
r
g
r
f
s
d
;
'
j
k
y
h
j
t
y
h


****************************

Is this your want?


0
 

Author Comment

by:Punker51
ID: 8091411
exactly thanx a lot m8
0
 

Author Comment

by:Punker51
ID: 8091417
very fast replying
0

Featured Post

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.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
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…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 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