请教VBSCRIPT高手,新手新帖,请大家多多帮助。
是这样的
在写页面时,需要有个功能,可以选择各个目录下的.TXT文件导入一些数据,如手机号码。现在我想实现导入这些数据后,把文件里导入的数据删掉,没导入的保留。
而不是删除文件。请教有没人帮我解决啊。现在问题困惑好几天了,希望大家帮帮小弟。
Sub btnImport_onclick strFileName=btnBrowse.value Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Dim fso,file,msg Set fso = CreateObject("Scripting.fileSystemObject") Set file = fso.OpenTextFile(strFileName,ForReading) iCount = 0 Do While Not file.AtEndOfStream and iCount < 100 fileTemp = file.ReadLine Num = Left(fileTemp, 3) Result = IsMatch(fileTemp, "^[0-9-]+$") and (Len(fileTemp) = 11) and ((Num="130")or(Num="131")or(Num="132")or(Num="133") or (Num="134")or(Num="135")or(Num="136")or(Num="137")or(Num="138")or(Num="139")or(Num="158")or(Num="159")or(Num="150")or(Num="151")or(Num="152")or(Num="157")or(Num="188")) if not Result then edtReceptNo.value = "" window.alert("无效的受理号码!") exit sub end if edtReceptNo.value = edtReceptNo.value + fileTemp + "," iCount = iCount + 1 Loop iTemp = len(edtReceptNo.value) - 1 edtReceptNo.value = left(edtReceptNo.value,iTemp) file.Close Set file = Nothing Set fso = NothingEnd Sub
dim lastCount = 0Sub btnImport_onclick strFileName=btnBrowse.value Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Dim fso,file,msg Set fso = CreateObject("Scripting.fileSystemObject") Set file = fso.OpenTextFile(strFileName,ForReading)[b] iCount = 0 Do While Not file.AtEndOfStream and iCount < lastCount fileTemp = file.ReadLine loop[/b] iCount = 0 Do While Not file.AtEndOfStream and iCount < 100 fileTemp = file.ReadLine Num = Left(fileTemp, 3) Result = IsMatch(fileTemp, "^[0-9-]+$") and (Len(fileTemp) = 11) and ((Num="130")or(Num="131")or(Num="132")or(Num="133") or (Num="134")or(Num="135")or(Num="136")or(Num="137")or(Num="138")or(Num="139")or(Num="158")or(Num="159")or(Num="150")or(Num="151")or(Num="152")or(Num="157")or(Num="188")) if not Result then edtReceptNo.value = "" window.alert("无效的受理号码!") exit sub end if edtReceptNo.value = edtReceptNo.value + fileTemp + "," iCount = iCount + 1 [b]lastCount = lastCount + 1[/b] Loop.......
[解决办法]
楼上的确实不错!