Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey Razor,
I figured out my script to string the bytes together into a new file.
Previously, I was reading a single file that already contained a set of exported data, searching for specific data in that file, and stringing everything together in a new file, but here my script was stringing everything together incorrectly.
Now, I'm opening/reading every file in a specific directory, looking for specific data in each file, then stringing that data together into a new file. I've been testing it out and I'm getting exactly what I need now.
Just wanted to let you know that I didn't give up on it.
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\ArchivedSANEW'} Where " _
& "ResultClass = CIM_DataFile")For Each objFile In FileList
strName = objFile.FileNameSet objFile = objFSO.OpenTextFile(objFile.Name, ForReading)
strContents = objFile.ReadAll
objFile.ClosestrContents = Replace(strContents, "~", "~" & vbCrLf)
arrLines = Split(strContents, vbCrLf)
For Each strLine in arrLines
If Left(strLine, 3) = "000" Then
StoreNumber = Mid(strLine, 6, 3)
TransNumber = Mid(strLine, 29, 6)
TransDate = Mid(strLine, 35, 8)
TransCancel = Mid(strLine, 52, 1)
TransType = Mid(strLine, 47, 3)
End IfIf Left(strLine, 3) = "021" Then
DiscountCode = Mid(strLine, 4, 8)
AmountBeforeDiscount = Mid(strLine, 12, 10)
DiscountAmount = Mid(strLine, 22, 10)
AmountAfterDiscount = Mid(strLine, 32, 10)
End IfIf Left(strLine, 3) = "028" Then
CoupCode = Mid(strLine, 14, 40)
strNewFile = strNewFile & StoreNumber & TransNumber & TransDate & TransCancel & TransType & _
DiscountCode & AmountBeforeDiscount & DiscountAmount & AmountAfterDiscount & CoupCode & VbCrLf
End IfIf Left(strLine, 3) = "077" Then
OriginalTransNumber = Mid(strLine, 4, 6)
strNewFile = strNewFile & StoreNumber & TransNumber & TransDate & TransCancel & TransType & _
" " & OriginalTransNumber & VbCrLf
End If
NextSet objFile = objFSO.CreateTextFile("C:\ArchivedSANEW\CouponCode.txt")
objFile.Write strNewFile
objFile.CloseNext

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |