Hi everyone,
I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.
I have been able to successfully read lines using:
Line Input #inputFile, inputLine ' read line into inputLine string
But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.
Thanks a lot for any help you might give me,
Anja 5 32415
"Anja" <an*******@googlemail.comwrote in news:1160842037.079468.300920
@b28g2000cwb.googlegroups.com:
Hi everyone,
I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.
I have been able to successfully read lines using:
Line Input #inputFile, inputLine ' read line into inputLine string
But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.
Thanks a lot for any help you might give me,
Anja
Air Code Function
Public Function ReadFile$(byval fileName$)
Dim fileNumber%
fileNumber = FreeFile()
Open fileName For Binary As #fileNumber
ReadFile = String(LOF(fileNumber), vbNullChar)
Get #fileNumber, , ReadFile
Close #fileNumber
End Function
--
Lyle Fairfield
Lyle Fairfield wrote:
"Anja" <an*******@googlemail.comwrote in news:1160842037.079468.300920
@b28g2000cwb.googlegroups.com:
Hi everyone,
I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.
I have been able to successfully read lines using:
Line Input #inputFile, inputLine ' read line into inputLine string
But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.
Thanks a lot for any help you might give me,
Anja
Air Code Function
Public Function ReadFile$(byval fileName$)
Dim fileNumber%
fileNumber = FreeFile()
Open fileName For Binary As #fileNumber
ReadFile = String(LOF(fileNumber), vbNullChar)
Get #fileNumber, , ReadFile
Close #fileNumber
End Function
--
Lyle Fairfield
Hi there,
Thanks for replying.
The line:
Get #fileNumber, , ReadFile
returns an error "Variable uses an automation type not supported in
Visual Basic".
I am using VBA under Access.
Thanks,
Anja
"Anja" <an*******@googlemail.comwrote in
news:11**********************@f16g2000cwb.googlegr oups.com:
>
Lyle Fairfield wrote:
>"Anja" <an*******@googlemail.comwrote in news:1160842037.079468.300920 @b28g2000cwb.googlegroups.com:
Hi everyone,
I have a question about text file reading with VBA. I want to read
he whole contents of the file in one string variable.
I have been able to successfully read lines using:
Line Input #inputFile, inputLine ' read line into inputLine string
But is there any input command that lets me read the whole file
into a string variable without worrying about delimiters and all
that.
Thanks a lot for any help you might give me,
Anja
Air Code Function
Public Function ReadFile$(byval fileName$) Dim fileNumber% fileNumber = FreeFile() Open fileName For Binary As #fileNumber ReadFile = String(LOF(fileNumber), vbNullChar) Get #fileNumber, , ReadFile Close #fileNumber End Function
-- Lyle Fairfield
Hi there,
Thanks for replying.
The line:
Get #fileNumber, , ReadFile
returns an error "Variable uses an automation type not supported in
Visual Basic".
I am using VBA under Access.
Me too. This works here in Canada:
Debug.Print ReadFile("C:\Documents and Settings\Lyle Fairfield\My
Documents\GeocacheTextFiles\(GCNHHP) MULTI-AGREEMENT CONLEY TRACT by
BigLittleZee.txt")
(that's all one line)
--
Lyle Fairfield
Hmm, posted this just the other day.
Sub ImportData(FileName As String)
Dim intFF As Integer
Dim strLine As String
Dim varLines As Variant
Dim intLine As Integer
intFF = FreeFile
Open FileName For Binary Access Read Lock Read Write As intFF
strLine = Space(LOF(intFF))
Get intFF, , strLine
Close intFF
varLines = Split(strLine, vbCrLf)
' Now you can step through the varLines array
' and put the relevant data into the correct
' fields in your table.
End Sub
--
Terry Kreft
"Anja" <an*******@googlemail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi everyone,
I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.
I have been able to successfully read lines using:
Line Input #inputFile, inputLine ' read line into inputLine string
But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.
Thanks a lot for any help you might give me,
Anja
"Anja" <an*******@googlemail.comwrote in
news:11**********************@b28g2000cwb.googlegr oups.com:
Hi everyone,
I have a question about text file reading with VBA. I want to read he
whole contents of the file in one string variable.
I have been able to successfully read lines using:
Line Input #inputFile, inputLine ' read line into inputLine string
But is there any input command that lets me read the whole file into a
string variable without worrying about delimiters and all that.
Thanks a lot for any help you might give me,
Anja
I tested Lyle's function on Win98/Office 8 with no problems.
Sub Test()
MsgBox (Len(ReadFile("C:\WINDOWS\Application Data\AVG7\Log\emc.log")))
End Sub
This worked too.
Function FileToOneString()
Dim MyReadNum As Integer
Dim theGuts As Variant
'--
Rem FileToOneString(FileIN$)
Dim FileIN$
FileIN$ = "C:\WINDOWS\Application Data\AVG7\Log\emc.log"
'--
MyReadNum = FreeFile
Open FileIN For Input As MyReadNum
theGuts = Input$(LOF(MyReadNum), MyReadNum)
Close MyReadNum
MsgBox "Length is " & Len(theGuts) & vbCrLf & Right(theGuts, 40)
FileToOneString = theGuts
End Function
My test file was about nine Megs. I'm not sure what the limit is.
Cheers,
Alan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael |
last post by:
I have a data application in a2k that I need to create two fixed width
text files and then combine them to a single file The first file is
header information and the second is transaction data. ...
|
by: Johnny Meredith |
last post by:
I have seven huge fixed width text file that I need to import to Access.
They contain headers, subtotals, etc. that are not needed. There is also
some corrupt data that we know about and can...
|
by: G.Esmeijer |
last post by:
Friends,
I would like to read a text file (fixed length formaated) really fast and
store the data into an Access database (2003).
Using the streamreader and reading line by line, separating the...
|
by: Yama |
last post by:
Hi
Is there a way using an Intranet ASP.NET web application to access a text file from a specified folder
The Logic
ReadTextFile.asp
-------------------
FILE =...
|
by: Eric A. Johnson |
last post by:
I'm trying to create a text file, write to it, close it, then reopen the
same file for reading (line by line). I've so far been able to successfully
open the file, write to it, then close it. I...
|
by: Wes Peters |
last post by:
Does anyone know of an article that deals with the subject of reading a
structured text file using VBA code in Access?
Thanks,
Wes
|
by: Roy |
last post by:
Hi,
Thanks for helping.I have an A2K Appl.Recently,one of the groups agreed
to provide data which I download into the access table.The problem is
this data which is sent in a text file.I am unable...
|
by: mfrsousa |
last post by:
hi there,
i have a huge large text file (350.000 lines) that i want to import to
a MS Acccess Database, of course i don't want to use Access, but do it
with C#.
i already have tried the...
|
by: Atran |
last post by:
Hello:
In this article: You will learn to Write or Read A Text File.
Let's Begin:
First Create a new project (ConsoleApp or WinApp).
And Make sure your program uses these namespaces:
using...
|
by: dm3281 |
last post by:
Hello, I have a text report from a mainframe that I need to parse.
The report has about a 2580 byte header that contains binary information
(garbage for the most part); although there are a...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |