[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


VB6 Loading from a test file

Posted on 2011-04-28
Medium Priority
Last Modified: 2012-06-27
I have a text file which I write to, it takes the following format

Random Text - line 1
User defined type - line 2
User defined type - line 2
User defined type - line 3

I want to be able to just read the file in with user defined types only, so what I did was read in the file, exclude the first line then write the rest to a temp file which II then read in as follows

       Open sTempFilename For Random Access Read As #1 Len = Len(uExport)
        i = 0
        While Not EOF(1)

I checked that when I wrote to the temp file the length of each line is 511, however the length of the user defined type is 512, the consequence of this is that when I am reading in the types from the temporary file after line 1 they start to go one character out.

Hope that makes sense, any help would be appreciated

Question by:rocky050371
LVL 76

Expert Comment

ID: 35483702
'Lines' implies text files with one or more line termination characters (line return and/or line feed). Binary and Random access do not expect this.

It sounds as if your UDT includes one more such characters than the file. Obviously you could try shortening your UDT by one character, and see what happens.
LVL 76

Expert Comment

ID: 35483716
What was the code to create the temporary file?

Author Comment

ID: 35483738
   Open sTempFilename For Output As #2
        While Not EOF(1)
            If i = 0 Then
                i = 1
                Input #1, sTemp
                Input #1, sTemp
                Print #2, sTemp
            End If
LVL 16

Expert Comment

ID: 35483885
Can you provide any sample data and a copy of your UDT so that we can see where the two don't match?

Otherwise, do you REALLY need to have the file open for RANDOM access?  It seems a pretty huge waste to create a temp file just to read the data.  I would think you should be able to access the file by openning it for BINARY Access.  That way, you can to a "Line Input" command to read the 1st text line, then use GET with no record number and your UDT to get the records (Get #1,,UDT).
LVL 28

Accepted Solution

Ark earned 2000 total points
ID: 35500041
Smth like this?
Dim strData as string
Open YourFile For Binary As #1
    strData = String(LOF(1),0)
    Get #1,,strData
Close #1
Dim arrData() As String
Dim i As Long
Open YourTempFile For OutPut As #1
   For I=1 To Ubound(arrData)
        Print #1,arrData(i)
Close #1

Open in new window


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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

873 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