VB script to copy valid data to another file

5 pts.
Tags:
Visual Basic
Visual Basic Script
I am new to Scripting (Vb).  I need to do the following thru VB script. Is this possible?

There are few VB scripts which is currently performing the file transfer function (transferring these files from the network drive to the application). Some times, this text file contain some junk data in the first few lines.Script which does the transfer will not transfer such files. I would like to know whether there is a way to delete this junk data and create a new file with a different extension in the same path which i could transfer later. Same path can have more than 1 file like this...

Data in the file looks something like this:

ÃRØ5ŠÂ� N¦ËÀ#=�³€¹“®i6(“ ¶L¦}¡Ï…#–üÕ��–Ì|/sÅ/¯—ؐ���Üäÿ�[ßïéü±ö§º8L…VE¼(·(o� 1     000007887728721798327407428397483978971098700000 970987943209989898989234324321432543265436 435432543623443234263252532342

I want to retrieve starting 00000 (the file can have only numbers in all the lines and nothing else). Right now, i am doing it manually. Copy it from 000007887 till the end of the file and then create a new file (since i know even that 1 and the spaces following that are junk). I would like some kind of script which could do this funcitonality...

 

 

 

 

  



Software/Hardware used:
VBSCRIPT

Answer Wiki

Thanks. We'll let you know when a new response is added.

You might find some nuggets in this…….

The ref to a bat file is just to make permissions easier change directory and the launch of this script is handled by a 3 line lat file which is not always necessary.

‘*************************************************************************************************************************
‘Author: Mike Johnson Sept 2009
‘Optimized for an Epicor Vantage ERP System
‘Purpose to modify the Trading Partner value on an outbound invoice to be the TP related to the
‘ShipTo’ rather than the ‘BillTo’
‘Also to make the PONum and Date/Time part of the file name for archive purposes
‘CAUTION THIS IS A LIVE SCRIPT THAT IS MOVING DATA.
‘*************************************************************************************************************************
‘This script is launched by a 3 line bat file ‘VantageTo810.bat’ that facilitates system run script permissions
’10′*********************************************************************************************************************
Modify_Invoice_Flat_Files ‘Calls a function
‘*************************************************************************************************************************
FUNCTION Modify_Invoice_Flat_Files
Dim objFldr, objFso, objFileIn, objFileOut
Dim strFilePath, strFileIn, strFileOut, strLineIn, strLineOut, strFullPath, strSection, strElement
Dim strFind, strReplaceWith, strTime, strStamp, strPO, strHajoca, strDest, strArchive
Dim aryLine
Dim intIndx
’19
Const conReading = 1
strFilePath = “\\Vantage-Server\Epicor\edi_data\outbound\810″
strDest = “\\epicor\evision\outbound\810\Transfer”
strArchive = “\\Vantage-Server\Epicor\edi_data\outbound\Archive_810″
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set objFldr = objFso.GetFolder(strFilePath)
FOR EACH f in objFldr.files
’27
strFileIn = objFso.GetFileName(f)
IF InStr(strFileIn, “Result”) = 0 THEN
strFullPath = strFilePath & “” & strFileIn
Set objFileIn = objFso.OpenTextFile(strFullPath, conReading)
DO UNTIL objFileIn.AtEndOfStream

strLineIn = objFileIn.ReadAll
aryLine = Split(strLineIn, “~”)
For i = 0 to uBound(aryLine)
IF i = 1171 THEN
’38
strPO = uCase(Trim(cStr(aryLine(i))))
END IF
IF i = 1183 AND uCase(Left(Trim(cStr(aryLine(i))), 6)) = “HAJOCA” THEN

strHajoca = “T”
END IF
IF i = 1235 AND strHajoca = “T” THEN

strFind = uCase(Trim(cStr(aryLine(i))))
IF Left(strFind, 3) <> “HAJ” THEN
’49
MsgBox “Was expecting HAJMID, HAJMTN, HAJPAC or HAJFLA at element 1236″ & VBCRLF _
& “Write down this error message and call IT.”
END IF
END IF
IF i = 1708 AND strHajoca = “T” THEN

strReplaceWith = uCase(Trim(cStr(aryLine(i))))
IF Left(strReplaceWith, 3) <> “HAJ” THEN
’58
MsgBox “Was expecting HAJMID, HAJMTN, HAJPAC or HAJFLA at element 1708″ & VBCRLF _
& “Write down this error message and call IT.”
END IF
END IF
NEXT
LOOP
strTime=Replace(TIME(),”:”,”-”)
strTime=Replace(strTime,” “,””)
strStamp=MONTH(DATE)&”-”&DAY(DATE)&”-”&RIGHT(YEAR(DATE),2)&”_”&strTime
strFileOut = “Result_” & strStamp & “_PO_” & strPO & “.txt”
strDest = strDest & “” & strFileOut
’70
strArchive = strArchive & “” & strFileOut
Set objFileOut = objFso.CreateTextFile(strDest, True)
IF strHajoca = “T” THEN

objFileOut.Write(Replace(strLineIn,strFind,strReplaceWith))
ELSE

objFileOut.Write(strLineIn)
END IF
Set objFileOut = objFso.CreateTextFile(strArchive, True)
IF strHajoca = “T” THEN
’82
objFileOut.Write(Replace(strLineIn,strFind,strReplaceWith))
ELSE

objFileOut.Write(strLineIn)
END IF
objFileIn.close
objFso.DeleteFile strFullPath, force
’90
END IF
NEXT

END FUNCTION
‘**************************************************************************************************************
Set objFldr = nothing
Set objFso = nothing
Set objFileIn = nothing
Set objFileOut = nothing
’100
strFilePath=””
strFileIn=””
strFileOut=””
strFullPath=””
strLineIn=””
strLineOut=””
strSection=””
strElement=””
strFind=””
strReplaceWith=””
strDest = “”
strArchive=””
aryLine=””
intIndx=””

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following