Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBScript - Stringing data in a new file

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,62628
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBScript - Stringing data in a new file
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VBScript - Stringing data in a new file - 7/23/2008 3:37:35 AM   
  skisalomon77

 

Posts: 3
Score: 0
Joined: 7/11/2008
Status: offline
Hey guys,

I've been working on this script for about a week and a half. Obviously I'm a beginner. Reading SBScript books helps, but learning from others who do this on a daily basis complements the reading.

My script is opening a text file, reading the first 3 bytes of each line, extracting data based on what those three bytes are through a series of IF THEN statements, then stringing that data together and writing it to a newly created file. 

Let's say the file that I'm opening looks like this:

0000000100100077000000002749042800062620082047030010000   0000000000000106262008002005010                                                                        
0000000100100368200000003682042801062620082049200010000   0000000000001506262008002005010                                                                        
02112      0000016900000000500000000119001
02810      03ss608                                                                                                                         
0000000200100203900000002039037420062120081231120010100   0000000000001506212008002005010                                                                        
077037417062120081226001002039

After I execute my script, my output looks like this:

001042800062620080030                                  
001042801062620080200                                  
00104280106262008020012      169000500011900                                  
001042801062620080200ss608                                   
002037420062120080120                                  
002037420062120080120                                              037417

The first line is fine because there was no corresponding 021, 028 or 077 strings associated with it.
With the second, third, and fourth lines, the first 21 bytes are identical, but my script created three separate lines, instead of writing everything on a single line.
The same with the fifth and sixth lines, the first 21 bytes are identical, but two lines were created instead of one.

Here's how I'm trying to get my output to look using the WriteLine function down below, but I'm having some issues.

001042800062620080030                                  
00104280106262008020012ss608 169000500011900                                                                                              
002037420062120080120                                            037417

Any help in pointing me in the write direction would be greatyly appreciated. Below is the scrip I'm using.

Option Explicit
Dim strContents, StoreNumber, TransNumber, TransDate, TransCancel, TransType, OriginalTransNumber
Dim DiscountCode, CoupCode, AmountBeforeDiscount, DiscountAmount, AmountAfterDiscount, objFSO, objFile, strNewFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\ArchivedSANEW\SAfilter.txt")
With objFSO.OpenTextFile("C:\ArchivedSANEW\SAextract.txt", 1) 
  Do Until .AtEndOfStream   
      strContents = .ReadLine

      If Mid(strContents, 1, 3) = "000" Then    
         StoreNumber = Mid(strContents, 6, 3)    
         TransNumber = Mid(strContents, 29, 6) 
         TransDate = Mid(strContents, 35, 8)   
         TransCancel = Mid(strContents, 52, 1) 
         TransType = Mid(strContents, 47, 3)
      End If
        
      If Mid(strContents, 1, 3) = "021" Then
         DiscountCode = Mid(strContents, 4, 8)  
         AmountBeforeDiscount = Mid(strContents, 17, 5)
         DiscountAmount = Mid(strContents, 27, 5)
         AmountAfterDiscount = Mid(strContents, 37, 5)
      Else
         DiscountCode = ""
         AmountBeforeDiscount = ""
         DiscountAmount = ""
         AmountAfterDiscount = ""
      End If
      If Mid(strContents, 1, 3) = "028" Then
         CoupCode = Mid(strContents, 14, 6)
      Else
         CoupCode = ""
      End If
      If Mid(strContents, 1, 3) = "077" Then
         OriginalTransNumber = Mid(strContents, 4, 6)
      Else
         OriginalTransNumber = ""
      End If
      strNewFile = strNewFile & StoreNumber & TransNumber & _
                   TransDate & TransCancel & TransType & _
                   DiscountCode & CoupCode & AmountBeforeDiscount & DiscountAmount & AmountAfterDiscount & "                                   " & OriginalTransNumber
                  
      objFile.WriteLine StoreNumber & TransNumber & _
                        TransDate & TransCancel & TransType & _                     
                        DiscountCode & CoupCode & AmountBeforeDiscount & DiscountAmount & AmountAfterDiscount & "                                   " & OriginalTransNumber
  Loop
End With

< Message edited by skisalomon77 -- 7/23/2008 3:38:59 AM >
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBScript - Stringing data in a new file Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts