int start() { int songrecord; songrecord=FileOpen("_record.csv", FILE_CSV|FILE_WRITE|FILE_READ,','); if(songrecord<=0)return; int FA_id=1114444; int myFA; FileWrite(songrecord,"1114443",0); FileWrite(songrecord,"1114444",0); FileWrite(songrecord,"1114445",0); FileSeek(songrecord, 0, SEEK_SET); while(!FileIsEnding(songrecord)) { myFA=StrToInteger(FileReadString(songrecord)); if(myFA==FA_id){ int pos=FileTell(songrecord); Alert(pos); FileSeek(songrecord, pos-2, SEEK_SET); FileWrite(songrecord,6.6); Alert(GetLastError() ); break; } } FileClose(songrecord); } 期望输出 1114443 0 1114444 6.6 1114445 0 请问要如何修改
不起作用呵~ 已将代码改为: =========================== int start() { int songrecord; songrecord=FileOpen("_record.csv", FILE_CSV|FILE_WRITE|FILE_READ,','); if(songrecord<=0)return; int FA_id=1114444; int myFA; FileWrite(songrecord,"1114443",0); FileWrite(songrecord,"1114444",0); FileWrite(songrecord,"1114445",0); FileSeek(songrecord, 0, SEEK_SET); while(!FileIsEnding(songrecord)) { myFA=StrToInteger(FileReadString(songrecord)); if(myFA==FA_id){ int pos=FileTell(songrecord); Alert(pos); FileClose(songrecord); songrecord=FileOpen("_record.csv", FILE_CSV|FILE_WRITE|FILE_READ,','); FileSeek(songrecord, pos-2, SEEK_SET); FileWrite(songrecord,6.6); Alert(GetLastError() ); break; } } FileClose(songrecord); } =========================== 输出结果为: 1114443 0 1114444 6.6 4445 0 "6.6"取代"0"后即占用了1114445的前三位
程序的问题,在于写入csv文件时,不是固定长度的字符串。这样就会出现,在原址写入新数据时,覆盖了后面的数据。 --------------------------------------------- 1。将FileWrite(songrecord,"1114445",0);改为: string str; str = "1114445"; FileWriteString(songrecord, str, StringLen(str)); str = 0; FileWriteString(songrecord, str, 10); FileWrite(songrecord, ""); --------------------------------------------- 2。将FileWrite(songrecord,6.6); 改为: str = 6.6; FileWriteString(songrecord, str, 10);