View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Per[_2_] Per[_2_] is offline
external usenet poster
 
Posts: 10
Default 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).