Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 59 Bad record length
I get this message when trying to read from a file opened as random vith the
get statement. I use Len=Len(record). The record is a user-defined type that only contains fixed-size variables (variables of type byte, integer, double and string*24, i.e. fixed length). I can open and read the file with an old program written with Borland TurboPascal 6.0. The Excel program is of type 2002. I dont understand why I get the message. If somebody has any sugestions, please answer! -- Per |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 59 Bad record length
Len is a VBA function. You can't assign a value to this function. change
the statement to Mylen = len(record) Turbo PASCAL probably ignores the error. "Per" wrote: I get this message when trying to read from a file opened as random vith the get statement. I use Len=Len(record). The record is a user-defined type that only contains fixed-size variables (variables of type byte, integer, double and string*24, i.e. fixed length). I can open and read the file with an old program written with Borland TurboPascal 6.0. The Excel program is of type 2002. I dont understand why I get the message. If somebody has any sugestions, please answer! -- Per |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 59 Bad record length
-- Per "Joel" skrev: Len is a VBA function. You can't assign a value to this function. change the statement to Mylen = len(record) Turbo PASCAL probably ignores the error. "Per" wrote: I get this message when trying to read from a file opened as random vith the get statement. I use Len=Len(record). The record is a user-defined type that only contains fixed-size variables (variables of type byte, integer, double and string*24, i.e. fixed length). I can open and read the file with an old program written with Borland TurboPascal 6.0. The Excel program is of type 2002. I dont understand why I get the message. If somebody has any sugestions, please answer! -- Per Thank you Joel, but your suggestion didn't help, the problem persisted. I supply part of the program code and the help suggestion from the VBA. If you or anybody else have other suggestions, please mail them! Per 'Defining the User-Data Type Type OperatorTid '9 byte Operatorkod As Integer Tp0 As Byte Tp1 As Byte Tp2 As Byte Tp3 As Byte Tp4 As Byte Tp5 As Byte Tp6 As Byte End Type Type Kolldat '9 byte Kd0 As Byte Kd1 As Byte Kd2 As Byte Kd3 As Byte Kd4 As Byte Kd5 As Byte Kd6 As Byte Kd7 As Byte Kd8 As Byte End Type Type Vertyp '16 byte Verif As Integer Verk2 As Integer Verk3 As Integer Verk4 As Integer Verk5 As Integer Verk6 As Integer Verk7 As Integer Verk8 As Integer End Type Type Transaktion '66 byte Logg As OperatorTid '9 byte Kolldatum As Kolldat '9 byte Verkonto As Vertyp '16 byte Transbelopp As Double '8 byte Transtext As String * 24 '24 byte End Type 'index verkonto kolldatum ' 0 Sekel ' 1 VerifNr Ã…r ' 2 baskonto D MÃ¥nad ' 3 baskonto K Dag ' 4 Medlem D k-siffra ' 5 Medlem K k-siffra ' 6 Underkonto D k-siffra ' 7 Underkonto K k-siffra ' 8 Stortbelopp Statuskod Dim TransIn As Transaktion, TransUt As Transaktion, VText As String * 24 - - - - - - - - - - - - - - 'Excerpt from the problem part of the program Medd = "Ange filnamn för indata" MittVärde = InputBox(Medd, Titel, Standard) IndataFilnamn = MittVärde FilvägIndata = IndataKatalog & "\" & IndataFilnamn IndataGrupp = Len(TransIn) Position = 1: rad = 1: Kol = 1 Textrad = "" Sheets("XBOK").Select Selection.Clear ChDir IndataKatalog InfilNr = FreeFile ' Hämta ledigt filnummer Open FilvägIndata For Random Access Read As #InfilNr Len = IndataGrupp Do While Not EOF(InfilNr) ' Sök efter filslutet. Get #InfilNr, Position, TransIn ' Läs en post. PascalTillBlad SkrivTillLista Position = Position + 1 rad = rad + 1 Loop Close #InfilNr - - - - - From the VBA Help instructions Bad record length (Error 59) The length of a record variable in a Get or Put statement must be the length specified in its corresponding Open statement. This error has the following causes and solutions: €¢ The record variable's length differs from the length specified in the corresponding Open statement. Make sure the sum of the sizes of fixed-length variables in the user-defined type defining the record variable's type is the same as the value stated in the Open statement's Len clause. In the following example, assume RecVar is a variable of the appropriate type. You can use the Len function to specify the length, as follows: Open MyFile As #1 Len = Len(RecVar) €¢ The variable in a Put statement is (or includes) a variable-length string. Because a 2-byte descriptor is always added to a variable-length string placed in a random access file with Put, the variable-length string must be at least 2 characters shorter than the record length specified in the Len clause of the Open statement. €¢ The variable in a Put statement is (or includes) a Variant. Like variable-length strings, Variant data types also require a 2-byte descriptor. Variants containing variable-length strings require a 4-byte descriptor. Therefore, for variable-length strings in a Variant, the string must be at least 4 bytes shorter than the record length specified in the Len clause. For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh). |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 59 Bad record length
I got the code to work by commented out the chdir. I did not get the same
error you had. I think the problem is with the permnissions of the directory you are using. I would add the following code to help locate the problem msgbox(Application.Path) <= find out which path you are using. ChDir IndataKatalog "Per" wrote: -- Per "Joel" skrev: Len is a VBA function. You can't assign a value to this function. change the statement to Mylen = len(record) Turbo PASCAL probably ignores the error. "Per" wrote: I get this message when trying to read from a file opened as random vith the get statement. I use Len=Len(record). The record is a user-defined type that only contains fixed-size variables (variables of type byte, integer, double and string*24, i.e. fixed length). I can open and read the file with an old program written with Borland TurboPascal 6.0. The Excel program is of type 2002. I dont understand why I get the message. If somebody has any sugestions, please answer! -- Per Thank you Joel, but your suggestion didn't help, the problem persisted. I supply part of the program code and the help suggestion from the VBA. If you or anybody else have other suggestions, please mail them! Per 'Defining the User-Data Type Type OperatorTid '9 byte Operatorkod As Integer Tp0 As Byte Tp1 As Byte Tp2 As Byte Tp3 As Byte Tp4 As Byte Tp5 As Byte Tp6 As Byte End Type Type Kolldat '9 byte Kd0 As Byte Kd1 As Byte Kd2 As Byte Kd3 As Byte Kd4 As Byte Kd5 As Byte Kd6 As Byte Kd7 As Byte Kd8 As Byte End Type Type Vertyp '16 byte Verif As Integer Verk2 As Integer Verk3 As Integer Verk4 As Integer Verk5 As Integer Verk6 As Integer Verk7 As Integer Verk8 As Integer End Type Type Transaktion '66 byte Logg As OperatorTid '9 byte Kolldatum As Kolldat '9 byte Verkonto As Vertyp '16 byte Transbelopp As Double '8 byte Transtext As String * 24 '24 byte End Type 'index verkonto kolldatum ' 0 Sekel ' 1 VerifNr Ã…r ' 2 baskonto D MÃ¥nad ' 3 baskonto K Dag ' 4 Medlem D k-siffra ' 5 Medlem K k-siffra ' 6 Underkonto D k-siffra ' 7 Underkonto K k-siffra ' 8 Stortbelopp Statuskod Dim TransIn As Transaktion, TransUt As Transaktion, VText As String * 24 - - - - - - - - - - - - - - 'Excerpt from the problem part of the program Medd = "Ange filnamn för indata" MittVärde = InputBox(Medd, Titel, Standard) IndataFilnamn = MittVärde FilvägIndata = IndataKatalog & "\" & IndataFilnamn IndataGrupp = Len(TransIn) Position = 1: rad = 1: Kol = 1 Textrad = "" Sheets("XBOK").Select Selection.Clear ChDir IndataKatalog InfilNr = FreeFile ' Hämta ledigt filnummer Open FilvägIndata For Random Access Read As #InfilNr Len = IndataGrupp Do While Not EOF(InfilNr) ' Sök efter filslutet. Get #InfilNr, Position, TransIn ' Läs en post. PascalTillBlad SkrivTillLista Position = Position + 1 rad = rad + 1 Loop Close #InfilNr - - - - - From the VBA Help instructions Bad record length (Error 59) The length of a record variable in a Get or Put statement must be the length specified in its corresponding Open statement. This error has the following causes and solutions: €¢ The record variable's length differs from the length specified in the corresponding Open statement. Make sure the sum of the sizes of fixed-length variables in the user-defined type defining the record variable's type is the same as the value stated in the Open statement's Len clause. In the following example, assume RecVar is a variable of the appropriate type. You can use the Len function to specify the length, as follows: Open MyFile As #1 Len = Len(RecVar) €¢ The variable in a Put statement is (or includes) a variable-length string. Because a 2-byte descriptor is always added to a variable-length string placed in a random access file with Put, the variable-length string must be at least 2 characters shorter than the record length specified in the Len clause of the Open statement. €¢ The variable in a Put statement is (or includes) a Variant. Like variable-length strings, Variant data types also require a 2-byte descriptor. Variants containing variable-length strings require a 4-byte descriptor. Therefore, for variable-length strings in a Variant, the string must be at least 4 bytes shorter than the record length specified in the Len clause. For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh). |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 59 Bad record length
-- Per "Joel" skrev: I got the code to work by commented out the chdir. I did not get the same error you had. I think the problem is with the permnissions of the directory you are using. I would add the following code to help locate the problem msgbox(Application.Path) <= find out which path you are using. ChDir IndataKatalog For some reason I don't understand it doesn't work on my computer. I have modified the program code so that I can read the file from the same directory as the workbook is stored in and also in the same directory as the msgbox(Application.Path) shows but nothing seems to help. Per |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error 59 Bad record length
Your file is probably a binary file. I included the VBA help instruction for
the OPEN and INPUT functions. I would try to open the file in BINARY mode. Ther are tips in the help below on using LEN with Binary files. ---------------------------------------------------------------------------------------------- Open Statement Enables input/output (I/O) to a file. Syntax Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength] The Open statement syntax has these parts: Part Description pathname Required. String expression that specifies a file name €” may include directory or folder, and drive. mode Required. Keyword specifying the file mode: Append, Binary, Input, Output, or Random. If unspecified, the file is opened for Random access. access Optional. Keyword specifying the operations permitted on the open file: Read, Write, or Read Write. lock Optional. Keyword specifying the operations restricted on the open file by other processes: Shared, Lock Read, Lock Write, and Lock Read Write. filenumber Required. A valid file number in the range 1 to 511, inclusive. Use the FreeFile function to obtain the next available file number. reclength Optional. Number less than or equal to 32,767 (bytes). For files opened for random access, this value is the record length. For sequential files, this value is the number of characters buffered. Remarks You must open a file before any I/O operation can be performed on it. Open allocates a buffer for I/O to the file and determines the mode of access to use with the buffer. If the file specified by pathname doesn't exist, it is created when a file is opened for Append, Binary, Output, or Random modes. If the file is already opened by another process and the specified type of access is not allowed, the Open operation fails and an error occurs. The Len clause is ignored if mode is Binary. Important In Binary, Input, and Random modes, you can open a file using a different file number without first closing the file. In Append and Output modes, you must close a file before opening it with a different file number. ---------------------------------------------------------------------------------------------- Input Function Returns String containing characters from a file opened in Input or Binary mode. Syntax Input(number, [#]filenumber) The Input function syntax has these parts: Part Description number Required. Any valid numeric expression specifying the number of characters to return. filenumber Required. Any valid file number. Remarks Data read with the Input function is usually written to a file with Print # or Put. Use this function only with files opened in Input or Binary mode. Unlike the Input # statement, the Input function returns all of the characters it reads, including commas, carriage returns, linefeeds, quotation marks, and leading spaces. With files opened for Binary access, an attempt to read through the file using the Input function until EOF returns True generates an error. Use the LOF and Loc functions instead of EOF when reading binary files with Input, or use Get when using the EOF function. Note Use the InputB function for byte data contained within text files. With InputB, number specifies the number of bytes to return rather than the number of characters to return. "Per" wrote: -- Per "Joel" skrev: I got the code to work by commented out the chdir. I did not get the same error you had. I think the problem is with the permnissions of the directory you are using. I would add the following code to help locate the problem msgbox(Application.Path) <= find out which path you are using. ChDir IndataKatalog For some reason I don't understand it doesn't work on my computer. I have modified the program code so that I can read the file from the same directory as the workbook is stored in and also in the same directory as the msgbox(Application.Path) shows but nothing seems to help. Per |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Saving a worksheet as . prn text file - record length | Excel Discussion (Misc queries) | |||
Unexplained "Bad Record Length" error / bug? | Excel Programming | |||
Converting from Excel into a fixed length record | Excel Programming | |||
fixed string length,even other record is copied | Excel Discussion (Misc queries) | |||
Variable-Length String causing error | Excel Programming |