【发布时间】:2016-05-23 11:16:28
【问题描述】:
我试图用 txtfile 中的信息替换 phc 表,但我没有在屏幕上获取信息。
re 是我要替换值的表 txtcabecalho 是人们必须选择的导入文件 reciboc 是我创建的用于存储 txt 文件中的值的光标,因此我可以在 re 上替换它们并将它们显示到屏幕上 sre 是表 re 的屏幕。
Local txtcabecalho
Use re
Delete all
txtcabecalho=getfile("txt")
Create cursor reciboc(rno n(10), rdata d(10), moeda c(3), no n(10), nome c(2), ccusto c(20), intid c(10), clbanco c(20), total float(19), totalmoeda float(19), ndoc n(3))
append from (txtcabecalho) delimited with tab
select reciboc
goto top
scan for !empty(reciboc.rno)
select re
append blank
replace re.rno with reciboc.rno
replace re.rdata with reciboc.rdata
replace re.moeda with reciboc.moeda
replace re.no with reciboc.no
replace re.nome with reciboc.nome
replace re.ccusto with reciboc.ccusto
replace re.intid with reciboc.intid
replace re.clbanco with reciboc.clbanco
replace re.total with reciboc.total
replace re.totalmoeda with reciboc.totalmoeda
replace re.ndoc with reciboc.ndoc
select re
endscan
sre.refresh()
谢谢!
更新
因此,如果我使用我选择的分隔符(例如使用制表符)创建我自己的文件,这实际上是有效的。这件事是我需要导入的文件就像使用空格作为空间持有者并且彼此没有分隔符。让我解释得更好。例如前 3 个字段 rno 和 rdata 和 moeda。
txt 文件类似于22014-12-23EUR
其中 2 是 rno,但后面有 9 个空格,就像占位符一样,用于更大的数字,使 rno(10) 接下来是 2014-12-23,它就在 rno 旁边,没有 rdata(10) 的定界 接下来是欧元的moeda,同样没有定界,是moeda(3)
许多字段将是空白的,并且那些 txt 文件带有占据整个字段长度的空格。基本上,字段长度用作分隔符,当为空时,它用空格填充。
你没听错吧?对不起,我不是英语母语。
更新
这里是一些txt文件22014-11-27EUR 208 799,00 799,00 00
请记住,在第一个数字 2 之前,有 9 个空格。 谢谢!
将用 2014-11-27 填充的 rdata 字段是 rdata d(10)
已编辑
当前代码:
Local txtcabecalho, fileconvert
Use re
zap
txtcabecalho=getfile("txt")
Create cursor reciboc(rno n(10), rdata d(10), moeda c(3), no n(10), nome c(2), ccusto c(20), intid c(10), gg c(20), chq c(20), clbanco c(20), total float(19), totalmoeda float(19), ndoc n(3))
fileconvert = filetostr(txtcabecalho)
chrtran(fileconvert,'-','')
strtofile(fileconvert, txtcabecalho)
append from (txtcabecalho) type sdf
scan
select re
append blank
replace rno with reciboc.rno
replace rdata with reciboc.rdata
replace moeda with reciboc.moeda
replace no with reciboc.no
replace nome with reciboc.nome
replace ccusto with reciboc.ccusto
replace intid with reciboc.intid
replace clbanco with reciboc.clbanco
replace total with reciboc.total
replace totalmoeda with reciboc.totalmoeda
replace ndoc with reciboc.ndoc
select re
endscan
select reciboc
browse title "resultado"
reindex
sre.refresh()
我得到的是this is what i get
还在想办法,我真的不知道啊
例如:第一行应该是:
RNO 2 RDATA 2014-11-27 NO 208
已编辑
其实这样就成功了啊
fileconvert = filetostr(txtcabecalho)
fileconvert2 = strtran(fileconvert,'-','')
strtofile(fileconvert2, txtcabecalho)
如果我需要进一步的帮助,我会更新我的问题!非常感谢你们!
已编辑
你们知道从txt文件浮点数转换成游标有什么问题吗?
例如,我得到了 799,20,但我只是显示为 799。数据类型设置为 totalmoeda f(19) 。这一定很简单,但我找不到!
【问题讨论】:
-
附带说明,当您需要发出多个替换命令时,不要发出单独的替换命令,而是发出一个。您可以像这样用一个替换多个替换:将 f1 替换为 'f1content',将 f2 替换为 'f2Content' ... 这样就可以通过一次替换进行替换。您的每次更换都会进行更换。在这里并不重要,但请记住,这会极大地影响性能(而且 VFP 开发人员对性能很疯狂)。
-
float 类型与 numeric 类型相同。如果需要小数,则必须将它们包含在列的定义中。无论数据类型如何,F(19) 都是整数。
-
我想办法做到这一点,但我不明白我应该如何做到这一点
标签: visual-foxpro foxpro dbase xbase