Home All Groups Group Topic Archive Search About

Random access file help

Author
1 Mar 2007 8:35 AM
sunny_side_up_2007
I have been given a file in quick basic which reads data from a random
access file.  I have tried to convert it to run in vb. The code is:
(note ARRAY, FILE$ and FILEEXTENSION$ are variables assigned a value)

DIM DM1(ARRAY), NL1(ARRAY), LP1(ARRAY), CP1(ARRAY), PS1(ARRAY),
RA1(ARRAY), CR1(ARRAY)
OPEN "R", #1, "A:" + FILE$ + FILEEXTENSION$, 16
FOR I% = 0 TO ARRAY
FIELD #1, 4 AS AAA$, 4 AS BBB$, 4 AS CCC$, 4 AS DDD$
GET #1, (I% + 1)
DM1(I%) = CVSMBF(AAA$)
NL1(I%) = CVSMBF(BBB$) * 1 / 1
LP1(I%) = CVSMBF(CCC$)
CP1(I%) = CVSMBF(DDD$)
CP1(I%) = CP1(I%) * CPM

>From looking on the help and forums I have tried this (below) as a
start but I'm really not sure I'm doing the right thing as it displays
loads of random characters when I output it to excel:

File = FreeFile
    Open "filename" For Input As File
    For i = 0 To 1
        Line Input #File, text
        Next i
Close File

If anyone could explain how to convert this to run in vb I would be
very grateful.

Cheers

Author
1 Mar 2007 10:00 AM
J French
On 1 Mar 2007 00:35:20 -0800, sunny_side_up_2***@yahoo.co.uk wrote:

Show quoteHide quote
>I have been given a file in quick basic which reads data from a random
>access file.  I have tried to convert it to run in vb. The code is:
>(note ARRAY, FILE$ and FILEEXTENSION$ are variables assigned a value)
>
> DIM DM1(ARRAY), NL1(ARRAY), LP1(ARRAY), CP1(ARRAY), PS1(ARRAY),
>RA1(ARRAY), CR1(ARRAY)
>OPEN "R", #1, "A:" + FILE$ + FILEEXTENSION$, 16
>FOR I% = 0 TO ARRAY
> FIELD #1, 4 AS AAA$, 4 AS BBB$, 4 AS CCC$, 4 AS DDD$
> GET #1, (I% + 1)
> DM1(I%) = CVSMBF(AAA$)
> NL1(I%) = CVSMBF(BBB$) * 1 / 1
> LP1(I%) = CVSMBF(CCC$)
> CP1(I%) = CVSMBF(DDD$)
> CP1(I%) = CP1(I%) * CPM
>
>>From looking on the help and forums I have tried this (below) as a
>start but I'm really not sure I'm doing the right thing as it displays
>loads of random characters when I output it to excel:
>
>File = FreeFile
>    Open "filename" For Input As File
>    For i = 0 To 1
>        Line Input #File, text
>        Next i
>Close File
>
>If anyone could explain how to convert this to run in vb I would be
>very grateful.

The FIELD statement is not supported in VB

You need to set up a UDT

Type TREC
    AAA As Single
    BBB As Single
    CCC As Single
    DDD As Single
End Type

Dim Rec as TREC

Filename$ = "A:" + FILE$ + FILEEXTENSION$
FileNo = FreeFile
Open Filename$ For Random Access Read As FileNo Len = 16
For I = 0 To Array
      Get# FileNo, I + 1, Rec
      DM1(I%) = Rec.AAA

Now the big problem here is CVSMBF()  means that the data is stored in
Microsoft Binary Format which is not the same as IEEE format

You really need to run up a little QBasic App to read the data and
write it out in IEEE format

  eg:  LSET AAA$ = MKS$( CVSMBF(AAA$) )

Incidentally the person who wrote that code was not a good programmer,
the FIELD statement only needs to be done once, not repeatedly.
Are all your drivers up to date? click for free checkup

Author
1 Mar 2007 4:48 PM
Jim Mack
sunny_side_up_2***@yahoo.co.uk wrote:
Show quoteHide quote
> I have been given a file in quick basic which reads data from a random
> access file.  I have tried to convert it to run in vb. The code is:
> (note ARRAY, FILE$ and FILEEXTENSION$ are variables assigned a value)
>
>  DIM DM1(ARRAY), NL1(ARRAY), LP1(ARRAY), CP1(ARRAY), PS1(ARRAY),
> RA1(ARRAY), CR1(ARRAY)
> OPEN "R", #1, "A:" + FILE$ + FILEEXTENSION$, 16
> FOR I% = 0 TO ARRAY
>  FIELD #1, 4 AS AAA$, 4 AS BBB$, 4 AS CCC$, 4 AS DDD$
>  GET #1, (I% + 1)
>  DM1(I%) = CVSMBF(AAA$)
>  NL1(I%) = CVSMBF(BBB$) * 1 / 1
>  LP1(I%) = CVSMBF(CCC$)
>  CP1(I%) = CVSMBF(DDD$)
>  CP1(I%) = CP1(I%) * CPM
>

Once you follow Jerry's advice to get the data into the program, you can use our free DLL to convert the MBF values to IEEE values. Find it as MBFIEE32.ZIP on our web site under "Products".

--

    Jim Mack
    MicroDexterity Inc
    www.microdexterity.com

Bookmark and Share