VBScript that read from one file to write in another

Hello,

Here I leave you a VBScript I did to modify a TXT file with the information of other file.

We read the file “C:\myfolder\information.txt” and fil the variables.
We read and write the file “C:\myfolder\final.txt” with the values we did
read before in the case is needed.

‘***************************************************************************
***********
Const ForReading=1
Const ForWriting=2
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
folder = “C:\myfolder\”
filePath = folder & “final.txt”
filePathinf = folder & “information.txt”
Set myFile = objFSO.OpenTextFile(filePath, ForReading, True)
Set myFileinf = objFSO.OpenTextFile(filePathinf, ForReading, True)
Set myTemp= objFSO.OpenTextFile(filePath & “.tmp”, ForWriting, True)

mypo = “12345678”
mypocheck = false

commonname = “name”
sname = “sname”
myplu = “123”

dim mygs1_128(400)
dim mypeso(400)
index = 1

Do While Not myFileinf.AtEndofStream
myLineinf = myFileinf.ReadLine

if InStr(myLineinf, mypo) then

mygs1_128(index) = mid(myLineinf,2,40)
mypeso(index) = mid(myLineinf,87,5)

index = index + 1

myitemcode = mid(myLineinf,60,5)
mygtin12 = mid(myLineinf,45,12)
sellbydate = mid(myLineinf,107,10)
packingdate = mid(myLineinf,94,10)

end if

Loop

index1 = 1
index = 1

Do While Not myFile.AtEndofStream
myLine = myFile.ReadLine

if InStr(myLine, “transaction_id='” & mypo & “‘>”) then
mypocheck = true

end if

if InStr(myLine, “itemcode”) then
myLine = ” ” & myitemcode &
“”

end if

if InStr(myLine, “plu_number”) then
myLine = ” ” & myplu &
“”

end if

if InStr(myLine, “commonname”) then
myLine = ” ” & commonname &
“”

end if

if InStr(myLine, “gtin_12″) then
myLine = ” ” & mygtin12 &
“”

end if

if InStr(myLine, “scientificname”) then
myLine = ” ” & sname &
“”

end if

if InStr(myLine, “sellbydate”) then
myLine = ” ” & sellbydate &
“”

end if

if InStr(myLine, “packagingdate”) then
myLine = ” ” & packingdate &
“”

end if

if InStr(myLine, “netweight”) and Instr(myLine,”averagenetweight”) = false
then
myLine = ” ” & mypeso(index) &
“”
index = index + 1
end if

if InStr(myLine, “gs1_128barcode”) then

myLine = ” ” &
mygs1_128(index1) & “”
index1 = index1 + 1
end if

myTemp.WriteLine myLine
Loop

myFile.Close
myTemp.Close
objFSO.DeleteFile(filePath)
objFSO.MoveFile filePath&”.tmp”, filePath

Wscript.Echo “TXT Ready”
‘***************************************************************************
******************************

Enjoy.

Leave a comment

Design a site like this with WordPress.com
Get started