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.

Functions to work on the web with vbscript

I will be sharing a research of functions you could use in vbscript for online web
access.

‘LIBRARIES OF FUNCTIONS

Function Searchweb(url,mystring)
gsearch = url & “#q=” & mystring
Set IE = CreateObject(“InternetExplorer.Application”)
set WshShell = WScript.CreateObject(“WScript.Shell”)
IE.Navigate gsearch
IE.Visible = True
Wscript.Sleep 6000
‘IE.Document.All.Item(“lst-ib”).Value = mystring
‘IE.Document.All.Item(pass).Value = valuep
WshShell.AppActivate “IE”
‘IE.Document.getElementById(submit).Click
‘IE.Document.getElementById(submit).Click
‘WshShell.SendKeys “{ENTER}”
‘return gsearch
End Function

Function Loginweb(url,user,valueu,pass,valuep,submit)
Set IE = CreateObject(“InternetExplorer.Application”)
set WshShell = WScript.CreateObject(“WScript.Shell”)
IE.Navigate url
IE.Visible = True
Wscript.Sleep 6000
IE.Document.All.Item(user).Value = valueu
IE.Document.All.Item(pass).Value = valuep
WshShell.AppActivate “IE”
IE.Document.getElementById(submit).Click
‘WshShell.SendKeys “{ENTER}”
End Function

Function Searchlink(url,linktext)
On error resume next
Dim WshShell, objIE, ElementCol
Dim LinkHref

LinkHref = url
‘This is the web site that will give the Certificate Security
Warning

Set WshShell = WScript.CreateObject(“WScript.Shell”)
Set objIE = CreateObject(“InternetExplorer.Application”)
objIE.Visible = False
‘No need to display IE before the “final” page has loaded (user never sees
the Certificate Warning page)
objIE.Navigate LinkHref ‘load web page
wshShell.AppActivate objIE

Do While objIE.Busy
wscript.sleep 100
Loop

Set ElementCol = objIE.Document.getElementsByTagName(“a”)
‘Get all links on web page
‘Grap/click the link we are looking for…
For Each Link In ElementCol
If Link.innerHTML = linktext Then
Link.Click
Exit For
End If
Next
objIE.Visible = True
end function

Function clickon(url,eleid)
‘Dim URL
Dim IE
Set IE = CreateObject(“internetexplorer.application”)
URL = url
IE.Visible = True
IE.Navigate URL

Do While IE.Busy
WScript.Sleep 100
Loop

IE.Document.getElementById(eleid).Click
end function

Function Find(StrString,URL)
Titre = “Find a String in a webpage”
‘URL = “https://www.facebook.com
Set ie = CreateObject(“InternetExplorer.Application”)
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
ie.Navigate(URL)
‘ie.Visible = 1
ie.Visible = 0
DO WHILE ie.busy
wscript.sleep 100
LOOP
Data = ie.document.documentElement.innertext
Set ie = Nothing
Set objRegex = new RegExp
objRegex.Pattern = StrString
objRegex.Global = False
objRegex.IgnoreCase = True
Set Matches = objRegex.Execute(Data)
For Each Match in Matches
MsgBox “We found this word : ” &vbCr& qq(Match.Value) & “in ” &
URL,64,Titre
Next
End Function

Function qq(strIn)
qq = Chr(34) & strIn & Chr(34)
End Function

Function Pause(NbMin)
wscript.sleep NbMin*1000*60
End Function

The Technology Journey Begins

Thanks for joining me!

Good company in a journey makes the way seem shorter. — Izaak Walton

This Blog it is to share my passion for the Technology, if you are a technology person lets share some content and information for the mutual grow.

Ronald Blanco

 

Design a site like this with WordPress.com
Get started