-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathПротек.vb_
108 lines (98 loc) · 3.56 KB
/
Протек.vb_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Option Explicit
On Error Resume Next
Dim DeviceOut, DeviceInp, FSO, FName, FDir, FLD, FF, FL, FN, S, NN,i,j,ZV,Doc,Docdat
Dim ArrayInp,ArrayOut, St
ReDim ArrayOut(21)
Const InExt="txt"
Const OutExt="spr"
Const OutPath="C:\Mail\Programs\In\"
Set FSO = CreateObject("Scripting.FileSystemObject")
'FDir=GetParm()
FDir="C:\Mail\Invoice\"&Mid(WScript.ScriptName,1,InStr(LCase(WScript.ScriptName),".vbs")-1)&"\"
ArrayInp=Split(FDir,";")
FDir=ArrayInp(0)
Set FLD = FSO.GetFolder(FDir)
Set FL = FLD.Files
For Each FF in FL
If FSO.GetExtensionName(LCase(FF.Name))=InExt then
i=0
FName=FDir&"\"&FF.Name
Set DeviceOut = FSO.CreateTextFile(FDir&"\"&Replace(FF.Name,".","_")&"."&OutExt, True)
Set DeviceInp = FSO.OpenTextFile(FName)
ArrayInp=Split(DeviceInp.ReadLine,vbTab)
DeviceOut.WriteLine("[Header]")
DeviceOut.WriteLine(ArrayInp(0)&";"&ArrayInp(1)&";"&ArrayInp(2)) ' çàãîëîâîê
DeviceOut.WriteLine("[Body]")
Do While not DeviceInp.AtEndOfStream ' òîâàðíûå ñòðîêè
St=DeviceInp.ReadLine
ArrayInp=Split(St,vbTab)
ArrayOut(0)=Replace(Trim(ArrayInp(0)),Chr(34),"") ' Êîä òîâàðà
ArrayOut(1)=Replace(Trim(ArrayInp(1)),Chr(34),"") ' Íàèìåíîâàíèå òîâàðà (ïîñòàâùèêà)
ArrayOut(2)=Replace(Trim(ArrayInp(2)),Chr(34),"") ' Ïðîèçâîäèòåëü
ArrayOut(3)=Replace(Trim(ArrayInp(3)),Chr(34),"") ' Ñòðàíà
ArrayOut(4)=Replace(Trim(ArrayInp(4)),Chr(34),"") ' Êîë-âî
ArrayOut(5)=Replace(ArrayInp(5),".",",")*(Replace(ArrayInp(6),".",",")+100)/100 ' Öåíà çàê. ????????????
ArrayOut(6)=Replace(Trim(ArrayInp(9)),Chr(34),"") ' Öåíà ïðîèçâ.
ArrayOut(7)=Replace(Trim(ArrayInp(5)),Chr(34),"") ' Öåíà çàê. áåç ÍÄÑ
ArrayOut(8)="" ' Öåíà çàê.
ArrayOut(9)="0" ' Íàöåíêà ïîñðåäíèêà
ArrayOut(10)="" ' Ðåçåðâ
ArrayOut(11)=Replace(ArrayInp(13),";",",") ' ÃÒÄ
ArrayOut(12)=ArrayInp(11)&"^"&Replace(ArrayInp(12),";","") 'ñåðòèôèêàòû
ArrayOut(13)=Replace(Trim(ArrayInp(11)),Chr(34),"") ' Ñåðèÿ
ArrayOut(14)="" ' ðåçåðâ
ArrayOut(15)=Trim(ArrayInp(14)) ' Ñðîê ãîäíîñòè (äàòà èñòå÷åíèÿ)
ArrayOut(16)="" ' Çàâîäñêîé øòðèõ-êîä
ArrayOut(17)="" ' Äàòà ðåãèñòðàöèè
ArrayOut(18)="" ' Öåíà ðååñòðà
ArrayOut(19)="" ' Òîðã.íàöåíêà èìïîðòåðà
ArrayOut(20)=Replace(Trim(ArrayInp(8)),Chr(34),"") ' Ñóììà ïî ñòðîêå
ArrayOut(21)="" ' Ïðèçíàê ÆÂËÑ
DeviceOut.WriteLine(Join(ArrayOut,";"))
if Err.Number then Exit Do
Loop
DeviceOut.Close: Set DeviceOut = nothing
DeviceInp.Close: Set DeviceInp = Nothing
'åñëè âîçíèêëè îøèáêè òî óäàëèì ñîçäàííûé ôàéë
if Err.Number then
FSO.DeleteFile (FDir&"\"&TableName&"."&OutExt)
Dim FOut
if not FSO.FileExists("error.log") then
Set FOut=FSO.CreateTextFile("error.log")
else
Set Fout=FSO.OpenTextFile("error.log",8,true)
end if
FOut.WriteLine("["&Now()&"] "&Err.Description&" ->"&WScript.ScriptName)
FOut.Close() : FOut=nothing
end if
Err.clear()
End If
Next
CopyFiles()
Set FL = nothing
Set FLD = nothing
Set FSO = nothing
Function GetParm()
Set DeviceInp = FSO.OpenTextFile("mail.tmp")
GetParm=DeviceInp.ReadLine()
DeviceInp.Close: Set DeviceInp = nothing
End Function
Function DelZero(St)
Dim i,Stmp
For i=1 to Len(St)
Stmp=Mid(St,i,1)
if Stmp<>"0" then exit for
next
DelZero=Mid(St,i,Len(St))
End Function
Function CopyFiles()
Set FL = FLD.Files
For Each FF in FL
if InStr(LCase(FF.Name),"."&OutExt) then
FSO.CopyFile FDir&FF.Name, OutPath&FF.Name
FSO.DeleteFile FDir&FF.Name
else
FSO.DeleteFile FDir&FF.Name
end if
Next
End Function