level 1
hetti110
楼主
一个简单的数据输出问题,print结果却不对。。。(有一列数据,就是price下的数据,输出位置不对, 还有最后一行不知道是什么。。。见下图)

代码如下:
TYPE goods ’自定义 goods 数据类型
num AS INTEGER ’有四个数据项,第一个num为整形
nam AS STRING * 14 ’第二个nam为14字节的字符串
price AS SINGLE ’第三个price为单精度型
stock AS INTEGER ’第四个stock为整形
END TYPE
CLS
DIM cloth AS goods ’定义cloth 为goods型数据
OPEN "d:\goods.dat" FOR RANDOM AS #1 LEN = LEN(cloth) ’新建“d:\ goods.dat”随机文件,文件记录长度为cloth长度
DO
READ cloth.num, cloth.nam, cloth.price, cloth.stock ’从DATA中读入数据给cloth赋值
IF cloth.num = 9999 THEN EXIT DO
PUT #1, , cloth
LOOP
DATA 1001,shirt,65,120,1002,skirt,76,108
DATA 1004,coat,231.5,67,1005,soaks,4.5,250
DATA 1006,pants,121.7,87,1008,underwear,34,86
DATA 9999,,,
PRINT "num", "name", "price", "stock" ’屏幕输出cloth数据
FOR i% = 1 TO LOF(1) / LEN(cloth)
GET #1, i%, cloth
PRINT cloth.num, cloth.nam, cloth.price, cloth.stock
NEXT i%
CLOSE
END
2013年09月27日 12点09分
1

代码如下:TYPE goods ’自定义 goods 数据类型
num AS INTEGER ’有四个数据项,第一个num为整形
nam AS STRING * 14 ’第二个nam为14字节的字符串
price AS SINGLE ’第三个price为单精度型
stock AS INTEGER ’第四个stock为整形
END TYPE
CLS
DIM cloth AS goods ’定义cloth 为goods型数据
OPEN "d:\goods.dat" FOR RANDOM AS #1 LEN = LEN(cloth) ’新建“d:\ goods.dat”随机文件,文件记录长度为cloth长度
DO
READ cloth.num, cloth.nam, cloth.price, cloth.stock ’从DATA中读入数据给cloth赋值
IF cloth.num = 9999 THEN EXIT DO
PUT #1, , cloth
LOOP
DATA 1001,shirt,65,120,1002,skirt,76,108
DATA 1004,coat,231.5,67,1005,soaks,4.5,250
DATA 1006,pants,121.7,87,1008,underwear,34,86
DATA 9999,,,
PRINT "num", "name", "price", "stock" ’屏幕输出cloth数据
FOR i% = 1 TO LOF(1) / LEN(cloth)
GET #1, i%, cloth
PRINT cloth.num, cloth.nam, cloth.price, cloth.stock
NEXT i%
CLOSE
END