在ASP中循环读取TXT文件内容问题?急再线等!
<%dimstatus,rline,MyFile,p,dialog_seq,goods_id,model,amount,mark,kwSetMyFileObject=Se...
<%
dim status,rline,MyFile,p,dialog_seq,goods_id,model,amount,mark,kw
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
'MyFile="D:\upload\dload.txt"
Set MyTextFile=MyFileObject.OpenTextFile("D:\load\upload.txt",1)
'打开dload.txt
IF not MyTextFile.atendofstream then
While Not MyTextFile.AtEndOfStream '到文件的末尾
rline =MyTextFile.ReadLine'读取一行
p=Instr(rline,",") '取得,号的位置
dialog_seq=Mid(rline,1,p-1) '取得,号前边的字符串(流水号)
rline=Mid(rline,p+1,Len(rline)-p) '设变量rline为,号后边的字符串
p=Instr(rline,",")
goods_id=Mid(rline,1,p-1) '取得,号前边的字符串(物资编码)
rline=Mid(rline,p+1,Len(rline)-p)
p=Instr(rline,",")
model=Mid(rline,1,p-1) '取得,号前边的字符串(型号)
rline=Mid(rline,p+1,Len(rline)-p)
p=Instr(rline,",")
kw=Mid(rline,1,p-1) '取得,号前边的字符串(库位)
rline=Mid(rline,p+1,Len(rline)-p)
p=Instr(rline,",")
amount=Mid(rline,1,p-1) '取得,号前边的字符串(数量)
response.write dialog_seq + " " + goods_id + " " + model + " " + kw + " " + amount &"<br>"
wend
MyTextFile.Close
else
response.write "数据为空"
response.end
end if
%>
TXT内容
ierp0000000000107057,5545108Y,H11Y-800-1,111,645
ierp0000000000107057,5545108Y,H11Y-800-1,111,1645
ierp0000000000107057,5545108Y,H11Y-800-1,111,645
ierp0000000000107057,5545108Y,H11Y-800-1,111,1645
ierp0000000000107057,5545108Y,H11Y-800-1,111,645
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
请高手看看我哪个地方错了怎么读不出TXT里面的东西了?
1楼不能去掉
p=Instr(rline,",")
amount=Mid(rline,1,p-1) '取得,号前边的字符串(数量)
我需要把数量显示出来!现在的问题是如果我在每行的最后面加个逗号就能正常读取了!我不想加这个逗号,请问程序该如何写? 展开
dim status,rline,MyFile,p,dialog_seq,goods_id,model,amount,mark,kw
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
'MyFile="D:\upload\dload.txt"
Set MyTextFile=MyFileObject.OpenTextFile("D:\load\upload.txt",1)
'打开dload.txt
IF not MyTextFile.atendofstream then
While Not MyTextFile.AtEndOfStream '到文件的末尾
rline =MyTextFile.ReadLine'读取一行
p=Instr(rline,",") '取得,号的位置
dialog_seq=Mid(rline,1,p-1) '取得,号前边的字符串(流水号)
rline=Mid(rline,p+1,Len(rline)-p) '设变量rline为,号后边的字符串
p=Instr(rline,",")
goods_id=Mid(rline,1,p-1) '取得,号前边的字符串(物资编码)
rline=Mid(rline,p+1,Len(rline)-p)
p=Instr(rline,",")
model=Mid(rline,1,p-1) '取得,号前边的字符串(型号)
rline=Mid(rline,p+1,Len(rline)-p)
p=Instr(rline,",")
kw=Mid(rline,1,p-1) '取得,号前边的字符串(库位)
rline=Mid(rline,p+1,Len(rline)-p)
p=Instr(rline,",")
amount=Mid(rline,1,p-1) '取得,号前边的字符串(数量)
response.write dialog_seq + " " + goods_id + " " + model + " " + kw + " " + amount &"<br>"
wend
MyTextFile.Close
else
response.write "数据为空"
response.end
end if
%>
TXT内容
ierp0000000000107057,5545108Y,H11Y-800-1,111,645
ierp0000000000107057,5545108Y,H11Y-800-1,111,1645
ierp0000000000107057,5545108Y,H11Y-800-1,111,645
ierp0000000000107057,5545108Y,H11Y-800-1,111,1645
ierp0000000000107057,5545108Y,H11Y-800-1,111,645
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
ierp0000000000107207,5525108Y,H11Y-800-1/2,111,641
请高手看看我哪个地方错了怎么读不出TXT里面的东西了?
1楼不能去掉
p=Instr(rline,",")
amount=Mid(rline,1,p-1) '取得,号前边的字符串(数量)
我需要把数量显示出来!现在的问题是如果我在每行的最后面加个逗号就能正常读取了!我不想加这个逗号,请问程序该如何写? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询