0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

レトロPCのためのBASIC講座 ランダムアクセスファイル操作

Last updated at Posted at 2025-06-10

前回のおさらい

前回は、シーケンシャルファイルの読書を行いました。

レトロPCのためのBASIC講座10

ランダムアクセスファイル

ランダムアクセスファイルはレコード長(記録する情報の長さ)が決まっているため、順次読み出す必要がなくN件目のレコードにアクセスできるファイルのことです。

ランダムアクセスファイルの読書

今回のプログラムでは、1~3レコードを書込み逆順で読んでいます。

RNDMF.BAS
1100 DATA 1,"Name1","Code001"
1110 DATA 2,"Name2","Code002"
1120 DATA 3,"Name3","Code003"
1130 OPEN "I","DF01.dat" AS #1
1140 FIELD #1,5 AS N$,20 AS DN$,20 AS DA$
1150 FOR I=1 TO 3
1155 PRINT "read:",I
1160 READ NU,NA$,CD$
1170 LSET N$=MKI$(NU)
1180 LSET DN$=NA$
1190 LSET DA$=CD$
1200 PUT #1
1210 NEXT I
1300 FOR I=3 TO 1 STEP -1
1310 GET #1,I
1320 PRINT "No:";CVI(N$)
1330 PRINT "Name:";DN$
1340 PRINT "Code:";CD$
1350 NEXT I
1360 '
1370 CLOSE #1

1140行目で1レコードの大きさを設定しており、
1170行目から1200行目が1レコードの書込み例です。
LSET命令では、フィールドに左詰めでデータをセットする命令です。

今回の動画

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?